2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2009 Jonas Fonseca <fonseca@diku.dk>
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html. See the License for the
12 * specific language governing permissions and limitations under the
13 * License. When distributing the software, include this License Header
14 * Notice in each file.
16 * This particular file is subject to the "Classpath" exception as provided
17 * by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the
19 * License Header, with the fields enclosed by brackets [] replaced by
20 * your own identifying information:
21 * "Portions Copyrighted [year] [name of copyright owner]"
25 * If you wish your version of this file to be governed by only the CDDL
26 * or only the GPL Version 2, indicate your decision by adding
27 * "[Contributor] elects to include this software in this distribution
28 * under the [CDDL or GPL Version 2] license." If you do not indicate a
29 * single choice of license, a recipient has the option to distribute
30 * your version of this file under either the CDDL, the GPL Version 2 or
31 * to extend the choice of license to its licensees as provided above.
32 * However, if you add GPL Version 2 code and therefore, elected the GPL
33 * Version 2 license, then the option applies only if the new code is
34 * made subject to such option by the copyright holder.
36 package org
.nbgit
.client
;
38 import java
.io
.FileNotFoundException
;
39 import org
.nbgit
.junit
.RepositoryTestCase
;
41 public class CheckoutBuilderTest
extends RepositoryTestCase
{
43 public CheckoutBuilderTest() {
44 super(CheckoutBuilderTest
.class.getSimpleName());
47 public void testCreate() throws Exception
{
48 assertNotNull(CheckoutBuilder
.create(repository
));
49 assertNotNull(CheckoutBuilder
.create(workDir
));
52 public void testFileSamePath() throws Exception
{
53 CheckoutBuilder
.create(repository
).
55 file(toWorkDirFile("a"), toWorkDirFile("a.txt")).
57 assertFile(getGoldenFile(), toWorkDirFile("a.txt"));
60 public void testFileOtherPath() throws Exception
{
61 CheckoutBuilder
.create(repository
).
63 file(toWorkDirFile("a"), toWorkDirFile("other/file.txt")).
65 assertFile(getGoldenFile(), toWorkDirFile("other/file.txt"));
68 public void testFileSupportsExecutable() throws Exception
{
69 CheckoutBuilder
.create(repository
).
71 file(toWorkDirFile("a"), toWorkDirFile("a.txt")).
73 assertTrue("File is not executable", !isExecutable(toWorkDirFile("a.txt")));
75 CheckoutBuilder
.create(repository
).
77 file(toWorkDirFile("a"), toWorkDirFile("a.exe")).
79 assertTrue("File is executable", isExecutable(toWorkDirFile("a.exe")));
82 public void testFiles() throws Exception
{
83 CheckoutBuilder
.create(repository
).
85 files(toFiles(workDir
, "a", "b/c", "d")).
87 IndexBuilder
.create(repository
).
88 addAll(toFiles(workDir
, "a", "b/c", "d")).
93 public void testBackup() throws Exception
{
94 toWorkDirFile("a").createNewFile();
95 CheckoutBuilder
.create(repository
).
97 file(toWorkDirFile("a"), toWorkDirFile("a")).
100 assertTrue("Checked out file exists", toWorkDirFile("a").exists());
101 assertTrue("Backup file exists", toWorkDirFile("a.orig").exists());
104 public void testBackupExisting() throws Exception
{
105 toWorkDirFile("a").createNewFile();
106 toWorkDirFile("a.orig").createNewFile();
107 CheckoutBuilder
.create(repository
).
109 file(toWorkDirFile("a"), toWorkDirFile("a")).
112 assertTrue("Checked out file exists", toWorkDirFile("a").exists());
113 assertTrue("Backup file exists", toWorkDirFile("a.0.orig").exists());
116 public void testRevisionNonExisting() throws Exception
{
118 CheckoutBuilder
.create(repository
).
120 fail("No exception thrown");
121 } catch (IllegalArgumentException error
) {
122 assertEquals("fail", error
.getMessage());
126 public void testFileNonExisting() throws Exception
{
128 CheckoutBuilder
.create(repository
).
130 file(toWorkDirFile("fail"), toWorkDirFile("fail.txt"));
131 fail("No exception thrown");
132 } catch (FileNotFoundException error
) {
133 assertEquals("fail", error
.getMessage());
137 public void testFilesNonExisting() throws Exception
{
139 CheckoutBuilder
.create(repository
).
141 files(toFiles(workDir
, "fail/1", "fail.2"));
142 fail("No exception thrown");
143 } catch (FileNotFoundException error
) {
144 assertEquals("fail/1", error
.getMessage());