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 java
.io
.IOException
;
40 import org
.nbgit
.junit
.RepositoryTestCase
;
42 public class IndexBuilderTest
extends RepositoryTestCase
{
44 public IndexBuilderTest() {
45 super(IndexBuilderTest
.class.getSimpleName());
48 public void testCreate() throws Exception
{
49 assertNotNull(IndexBuilder
.create(repository
));
50 assertNotNull(IndexBuilder
.create(workDir
));
53 public void testWriteUnmodified() throws Exception
{
54 copyFile(toGitDirFile("index"), toGitDirFile("index.orig"));
55 IndexBuilder
.create(repository
).write();
56 assertFile(toGitDirFile("index.orig"), toGitDirFile("index"));
59 public void testAdd() throws Exception
{
60 IndexBuilder
.create(repository
).
61 add(toWorkDirFile("d")).
66 public void testAddModified() throws Exception
{
67 IndexBuilder
.create(repository
).
68 add(toWorkDirFile("d")).
73 public void testAddSupportsExecutable() throws Exception
{
74 IndexBuilder
.create(repository
).
75 add(toWorkDirFile("d.exe")).
80 public void testAddModifiedSupportsExecutable() throws Exception
{
81 IndexBuilder
.create(repository
).
82 add(toWorkDirFile("d.exe")).
87 public void testAddAll() throws Exception
{
88 IndexBuilder
.create(repository
).
89 addAll(toFiles(workDir
, "b/e/f", "d", "g/h")).
94 public void testAddAllUnordered() throws Exception
{
95 IndexBuilder
.create(repository
).
96 addAll(toFiles(workDir
, "2", "3", "1")).
101 public void testDelete() throws Exception
{
102 IndexBuilder
.create(repository
).
103 delete(toWorkDirFile("b/e/f")).
108 public void testDeleteAll() throws Exception
{
109 IndexBuilder
.create(repository
).
110 deleteAll(toFiles(workDir
, "a", "b/e/f", "d")).
115 public void testDeleteAllUnordered() throws Exception
{
116 IndexBuilder
.create(repository
).
117 deleteAll(toFiles(workDir
, "d", "b/e/f", "b/c")).
122 public void testMove() throws Exception
{
123 toWorkDirFile("b/e/f").renameTo(toWorkDirFile("f"));
124 IndexBuilder
.create(repository
).
125 move(toWorkDirFile("b/e/f"), toWorkDirFile("f")).
130 public void testMoveSupportsExecutable() throws Exception
{
131 toWorkDirFile("b/e/f").renameTo(toWorkDirFile("f.exe"));
132 setExecutable(toWorkDirFile("f.exe"), true);
133 IndexBuilder
.create(repository
).
134 move(toWorkDirFile("b/e/f"), toWorkDirFile("f.exe")).
139 public void testLog() throws Exception
{
140 String
[] expectedMessages
= {
146 toWorkDirFile("add").createNewFile();
147 toWorkDirFile("to").createNewFile();
148 IndexBuilder
.create(repository
).
150 add(toWorkDirFile("add")).
151 add(toWorkDirFile("modified")).
152 delete(toWorkDirFile("delete")).
153 move(toWorkDirFile("from"), toWorkDirFile("to"));
154 assertEquals(expectedMessages
.length
, loggerMessages
.size());
155 for (int i
= 0; i
< expectedMessages
.length
; i
++)
156 assertEquals(expectedMessages
[i
], loggerMessages
.get(i
));
159 public void testAddNonExisting() throws Exception
{
161 IndexBuilder
.create(repository
).
162 add(toWorkDirFile("fail"));
163 fail("No exception thrown");
164 } catch (IOException error
) {
165 assertErrorPath(error
, "fail");
169 public void testAddAllNonExisting() throws Exception
{
171 IndexBuilder
.create(repository
).
172 addAll(toFiles(workDir
, "fail/1", "fail/2"));
173 fail("No exception thrown");
174 } catch (IOException error
) {
175 assertErrorPath(error
, "fail/1");
179 public void testMoveDestinationNonExisting() throws Exception
{
181 IndexBuilder
.create(repository
).
182 move(toWorkDirFile("a"), toWorkDirFile("fail"));
183 fail("No exception thrown");
184 } catch (IOException error
) {
185 assertErrorPath(error
, "fail");
189 private void assertErrorPath(IOException error
, String path
) {
190 assertTrue(error
.getMessage().startsWith(toWorkDirFile(path
).getPath()));