diff options
Diffstat (limited to 'org.eclipse.jgit.test')
18 files changed, 201 insertions, 76 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java index 910e3a958d..ad3ff60a00 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java @@ -53,7 +53,6 @@ import java.io.InputStream; import org.eclipse.jgit.api.errors.PatchApplyException; import org.eclipse.jgit.api.errors.PatchFormatException; -import org.eclipse.jgit.diff.DiffFormatterReflowTest; import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.junit.RepositoryTestCase; import org.junit.Test; @@ -86,9 +85,7 @@ public class ApplyCommandTest extends RepositoryTestCase { return git .apply() - .setPatch( - DiffFormatterReflowTest.class.getResourceAsStream(name - + ".patch")).call(); + .setPatch(getTestResource(name + ".patch")).call(); } @Test @@ -189,8 +186,7 @@ public class ApplyCommandTest extends RepositoryTestCase { } private static byte[] readFile(final String patchFile) throws IOException { - final InputStream in = DiffFormatterReflowTest.class - .getResourceAsStream(patchFile); + final InputStream in = getTestResource(patchFile); if (in == null) { fail("No " + patchFile + " test vector"); return null; // Never happens @@ -206,4 +202,9 @@ public class ApplyCommandTest extends RepositoryTestCase { in.close(); } } + + private static InputStream getTestResource(final String patchFile) { + return ApplyCommandTest.class.getClassLoader() + .getResourceAsStream("org/eclipse/jgit/diff/" + patchFile); + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index c2c8317d94..91ced0a596 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java @@ -121,7 +121,7 @@ public class BranchCommandTest extends RepositoryTestCase { Git localGit = new Git(localRepository); StoredConfig config = localRepository.getConfig(); RemoteConfig rc = new RemoteConfig(config, "origin"); - rc.addURI(new URIish(remoteRepository.getDirectory().getPath())); + rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath())); rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); rc.update(config); config.save(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index 31f909a5f2..56c1201760 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java @@ -110,7 +110,7 @@ public class CloneCommandTest extends RepositoryTestCase { File directory = createTempDirectory("testCloneRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); @@ -142,7 +142,7 @@ public class CloneCommandTest extends RepositoryTestCase { CloneCommand command = Git.cloneRepository(); command.setBare(true); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertEquals(new RefSpec("+refs/heads/*:refs/heads/*"), @@ -162,7 +162,7 @@ public class CloneCommandTest extends RepositoryTestCase { CloneCommand command = Git.cloneRepository(); command.setBranch("refs/heads/master"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -177,7 +177,7 @@ public class CloneCommandTest extends RepositoryTestCase { command = Git.cloneRepository(); command.setBranch("refs/heads/master"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setNoCheckout(true); git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -192,7 +192,7 @@ public class CloneCommandTest extends RepositoryTestCase { command = Git.cloneRepository(); command.setBranch("refs/heads/master"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setBare(true); git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -209,7 +209,7 @@ public class CloneCommandTest extends RepositoryTestCase { CloneCommand command = Git.cloneRepository(); command.setBranch("test"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -223,7 +223,7 @@ public class CloneCommandTest extends RepositoryTestCase { CloneCommand command = Git.cloneRepository(); command.setBranch("tag-initial"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -242,7 +242,7 @@ public class CloneCommandTest extends RepositoryTestCase { command.setBranchesToClone(Collections .singletonList("refs/heads/master")); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); @@ -257,7 +257,7 @@ public class CloneCommandTest extends RepositoryTestCase { command.setBranchesToClone(Collections .singletonList("refs/heads/master")); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setBare(true); git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -284,14 +284,14 @@ public class CloneCommandTest extends RepositoryTestCase { File directory = createTempDirectory(dirName); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); // clone again command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); try { git2 = command.call(); // we shouldn't get here @@ -310,7 +310,7 @@ public class CloneCommandTest extends RepositoryTestCase { File directory = createTempDirectory("testCloneRepositoryWithMultipleHeadBranches"); CloneCommand clone = Git.cloneRepository(); clone.setDirectory(directory); - clone.setURI("file://" + git.getRepository().getWorkTree().getPath()); + clone.setURI(fileUri()); Git git2 = clone.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); @@ -343,7 +343,7 @@ public class CloneCommandTest extends RepositoryTestCase { CloneCommand clone = Git.cloneRepository(); clone.setDirectory(directory); clone.setCloneSubmodules(true); - clone.setURI("file://" + git.getRepository().getWorkTree().getPath()); + clone.setURI(fileUri()); Git git2 = clone.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); @@ -458,7 +458,7 @@ public class CloneCommandTest extends RepositoryTestCase { File directory = createTempDirectory("testCloneRepository1"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertFalse(git2 @@ -476,7 +476,7 @@ public class CloneCommandTest extends RepositoryTestCase { directory = createTempDirectory("testCloneRepository2"); command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); git2 = command.call(); addRepoToClose(git2.getRepository()); assertTrue(git2 @@ -492,7 +492,7 @@ public class CloneCommandTest extends RepositoryTestCase { directory = createTempDirectory("testCloneRepository2"); command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); git2 = command.call(); addRepoToClose(git2.getRepository()); assertTrue(git2 @@ -502,4 +502,8 @@ public class CloneCommandTest extends RepositoryTestCase { ConfigConstants.CONFIG_KEY_REBASE, false)); } + + private String fileUri() { + return "file://" + git.getRepository().getWorkTree().getAbsolutePath(); + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java index f31276dee4..a853d6ab8f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java @@ -82,7 +82,7 @@ public class LsRemoteCommandTest extends RepositoryTestCase { File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setCloneAllBranches(true); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -99,7 +99,7 @@ public class LsRemoteCommandTest extends RepositoryTestCase { File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setCloneAllBranches(true); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -116,7 +116,7 @@ public class LsRemoteCommandTest extends RepositoryTestCase { File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setCloneAllBranches(true); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -130,10 +130,14 @@ public class LsRemoteCommandTest extends RepositoryTestCase { @Test public void testLsRemoteWithoutLocalRepository() throws Exception { - String uri = "file://" + git.getRepository().getWorkTree().getPath(); + String uri = fileUri(); Collection<Ref> refs = Git.lsRemoteRepository().setRemote(uri).setHeads(true).call(); assertNotNull(refs); assertEquals(2, refs.size()); } + private String fileUri() { + return "file://" + git.getRepository().getWorkTree().getAbsolutePath(); + } + } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java index 67e1879d37..29146dc585 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java @@ -1340,7 +1340,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertNull(db.readMergeCommitMsg()); Status stat = git.status().call(); - assertEquals(StatusCommandTest.set("file2", "file3"), stat.getAdded()); + assertEquals(Sets.of("file2", "file3"), stat.getAdded()); } @Test @@ -1396,7 +1396,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertNull(db.readMergeCommitMsg()); Status stat = git.status().call(); - assertEquals(StatusCommandTest.set("file3"), stat.getAdded()); + assertEquals(Sets.of("file3"), stat.getAdded()); } @Test @@ -1450,7 +1450,7 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals("\nConflicts:\n\tfile2\n", db.readMergeCommitMsg()); Status stat = git.status().call(); - assertEquals(StatusCommandTest.set("file2"), stat.getConflicting()); + assertEquals(Sets.of("file2"), stat.getConflicting()); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java index 8d22a1b58a..c03ced563f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java @@ -139,7 +139,8 @@ public class PullCommandTest extends RepositoryTestCase { assertEquals(sourceCommit.getId(), mergedCommits[1]); RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult .getNewHead()); - String message = "Merge branch 'master' of " + db.getWorkTree(); + String message = "Merge branch 'master' of " + + db.getWorkTree().getAbsolutePath(); assertEquals(message, mergeCommit.getShortMessage()); } @@ -255,7 +256,7 @@ public class PullCommandTest extends RepositoryTestCase { config .addURI(new URIish(source.getRepository().getWorkTree() - .getPath())); + .getAbsolutePath())); config.addFetchRefSpec(new RefSpec( "+refs/heads/*:refs/remotes/origin/*")); config.update(targetConfig); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java index 993e16f5e9..25534fdda6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java @@ -319,7 +319,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase { config .addURI(new URIish(source.getRepository().getWorkTree() - .getPath())); + .getAbsolutePath())); config.addFetchRefSpec(new RefSpec( "+refs/heads/*:refs/remotes/origin/*")); config.update(targetConfig); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/Sets.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/Sets.java new file mode 100644 index 0000000000..edfab551ab --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/Sets.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011, Christian Halstrick <christian.halstrick@sap.com> + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.api; + +import java.util.HashSet; +import java.util.Set; + +class Sets { + static <T> Set<T> of(T... elements) { + Set<T> ret = new HashSet<T>(); + for (T element : elements) + ret.add(element); + return ret; + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java index 8b3e87f2dc..47650232b3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java @@ -48,8 +48,6 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; -import java.util.HashSet; -import java.util.Set; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.NoFilepatternException; @@ -82,12 +80,12 @@ public class StatusCommandTest extends RepositoryTestCase { writeTrashFile("c", "content of c"); git.add().addFilepattern("a").addFilepattern("b").call(); Status stat = git.status().call(); - assertEquals(set("a", "b"), stat.getAdded()); + assertEquals(Sets.of("a", "b"), stat.getAdded()); assertEquals(0, stat.getChanged().size()); assertEquals(0, stat.getMissing().size()); assertEquals(0, stat.getModified().size()); assertEquals(0, stat.getRemoved().size()); - assertEquals(set("c"), stat.getUntracked()); + assertEquals(Sets.of("c"), stat.getUntracked()); git.commit().setMessage("initial").call(); writeTrashFile("a", "modified content of a"); @@ -96,12 +94,12 @@ public class StatusCommandTest extends RepositoryTestCase { git.add().addFilepattern("a").addFilepattern("d").call(); writeTrashFile("a", "again modified content of a"); stat = git.status().call(); - assertEquals(set("d"), stat.getAdded()); - assertEquals(set("a"), stat.getChanged()); + assertEquals(Sets.of("d"), stat.getAdded()); + assertEquals(Sets.of("a"), stat.getChanged()); assertEquals(0, stat.getMissing().size()); - assertEquals(set("b", "a"), stat.getModified()); + assertEquals(Sets.of("b", "a"), stat.getModified()); assertEquals(0, stat.getRemoved().size()); - assertEquals(set("c"), stat.getUntracked()); + assertEquals(Sets.of("c"), stat.getUntracked()); git.add().addFilepattern(".").call(); git.commit().setMessage("second").call(); @@ -122,8 +120,8 @@ public class StatusCommandTest extends RepositoryTestCase { assertEquals(0, stat.getChanged().size()); assertEquals(0, stat.getMissing().size()); assertEquals(0, stat.getModified().size()); - assertEquals(set("a"), stat.getRemoved()); - assertEquals(set("a"), stat.getUntracked()); + assertEquals(Sets.of("a"), stat.getRemoved()); + assertEquals(Sets.of("a"), stat.getUntracked()); git.commit().setMessage("t").call(); writeTrashFile("sub/a", "sub-file"); @@ -153,25 +151,18 @@ public class StatusCommandTest extends RepositoryTestCase { // filter on an existing file stat = git.status().addPath("a").call(); - assertEquals(set("a"), stat.getModified()); + assertEquals(Sets.of("a"), stat.getModified()); // filter on an existing folder stat = git.status().addPath("D").call(); - assertEquals(set("D/b", "D/D/d"), stat.getModified()); + assertEquals(Sets.of("D/b", "D/D/d"), stat.getModified()); // filter on an existing folder and file stat = git.status().addPath("D/D").addPath("a").call(); - assertEquals(set("a", "D/D/d"), stat.getModified()); + assertEquals(Sets.of("a", "D/D/d"), stat.getModified()); // do not filter at all stat = git.status().call(); - assertEquals(set("a", "D/b", "D/D/d"), stat.getModified()); - } - - public static Set<String> set(String... elements) { - Set<String> ret = new HashSet<String>(); - for (String element : elements) - ret.add(element); - return ret; + assertEquals(Sets.of("a", "D/b", "D/D/d"), stat.getModified()); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java index efdcfeb472..280d6040cc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java @@ -129,7 +129,8 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase { builder.setMustExist(true); Repository repo2 = builder.build(); - assertEquals(repo1.getDirectory(), repo2.getDirectory()); + assertEquals(repo1.getDirectory().getAbsolutePath(), repo2 + .getDirectory().getAbsolutePath()); assertEquals(dir, repo2.getWorkTree()); } @@ -167,7 +168,8 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase { builder.setWorkTree(dir); builder.findGitDir(dir); - assertEquals(repo1.getDirectory(), builder.getGitDir()); + assertEquals(repo1.getDirectory().getAbsolutePath(), builder + .getGitDir().getAbsolutePath()); builder.setMustExist(true); Repository repo2 = builder.build(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java index 17c44dce82..902416bdff 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java @@ -61,7 +61,14 @@ public class FileSnapshotTest { private List<File> files = new ArrayList<File>(); - private final File trash = new File(new File("target"), "trash"); + private File trash; + + @Before + public void setUp() throws Exception { + trash = File.createTempFile("tmp_", ""); + trash.delete(); + assertTrue("mkdir " + trash, trash.mkdir()); + } @Before @After diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java index 31938b98b3..ee845c5325 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.storage.file; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.File; @@ -55,6 +56,7 @@ import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.IO; import org.junit.After; +import org.junit.Before; import org.junit.Test; public class FileBasedConfigTest { @@ -73,7 +75,14 @@ public class FileBasedConfigTest { private static final String CONTENT2 = "[" + USER + "]\n\t" + NAME + " = " + BOB + "\n"; - private final File trash = new File(new File("target"), "trash"); + private File trash; + + @Before + public void setUp() throws Exception { + trash = File.createTempFile("tmp_", ""); + trash.delete(); + assertTrue("mkdir " + trash, trash.mkdir()); + } @After public void tearDown() throws Exception { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java index 2b9c107778..383ff5011c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java @@ -171,8 +171,10 @@ public class SubmoduleWalkTest extends RepositoryTestCase { Repository subRepo = gen.getRepository(); addRepoToClose(subRepo); assertNotNull(subRepo); - assertEquals(modulesGitDir, subRepo.getDirectory()); - assertEquals(new File(db.getWorkTree(), path), subRepo.getWorkTree()); + assertEquals(modulesGitDir.getAbsolutePath(), + subRepo.getDirectory().getAbsolutePath()); + assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(), + subRepo.getWorkTree().getAbsolutePath()); assertFalse(gen.next()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java index b9691836b6..28a3f4428e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java @@ -231,7 +231,7 @@ public class TransportTest extends SampleDataRepositoryTestCase { @Test public void testLocalTransportFetchWithoutLocalRepository() throws Exception { - URIish uri = new URIish("file://" + db.getWorkTree().getPath()); + URIish uri = new URIish("file://" + db.getWorkTree().getAbsolutePath()); transport = Transport.open(uri); FetchConnection fetchConnection = transport.openFetch(); try { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java index df39f2b9d8..7b1627854f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java @@ -57,12 +57,13 @@ import org.junit.Before; import org.junit.Test; public class FileUtilTest { - - private final File trash = new File(new File("target"), "trash"); + private File trash; @Before public void setUp() throws Exception { - assertTrue(trash.mkdirs()); + trash = File.createTempFile("tmp_", ""); + trash.delete(); + assertTrue("mkdir " + trash, trash.mkdir()); } @After diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java index 5975d37871..83a53b9a6d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java @@ -70,9 +70,9 @@ public class AutoCRLFInputStreamTest { @Test public void testBoundary() throws IOException { for (int i = AutoCRLFInputStream.BUFFER_SIZE - 10; i < AutoCRLFInputStream.BUFFER_SIZE + 10; i++) { - String s1 = AutoCRLFOutputStreamTest.repeat("a", i); + String s1 = Strings.repeat("a", i); assertNoCrLf(s1, s1); - String s2 = AutoCRLFOutputStreamTest.repeat("\0", i); + String s2 = Strings.repeat("\0", i); assertNoCrLf(s2, s2); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java index 6cb31050f4..a72d33cd51 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java @@ -72,21 +72,13 @@ public class AutoCRLFOutputStreamTest { @Test public void testBoundary() throws IOException { for (int i = AutoCRLFOutputStream.BUFFER_SIZE - 10; i < AutoCRLFOutputStream.BUFFER_SIZE + 10; i++) { - String s1 = repeat("a", i); + String s1 = Strings.repeat("a", i); assertNoCrLf(s1, s1); - String s2 = repeat("\0", i); + String s2 = Strings.repeat("\0", i); assertNoCrLf(s2, s2); } } - public static String repeat(String input, int size) { - StringBuilder sb = new StringBuilder(input.length() * size); - for (int i = 0; i < size; i++) - sb.append(input); - String s = sb.toString(); - return s; - } - private void assertNoCrLf(String string, String string2) throws IOException { assertNoCrLfHelper(string, string2); // \u00e5 = LATIN SMALL LETTER A WITH RING ABOVE diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/Strings.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/Strings.java new file mode 100644 index 0000000000..3d9b054eeb --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/Strings.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011, 2013 Robin Rosenberg + * Copyright (C) 2013 Robin Stocker + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.eclipse.jgit.util.io; + +class Strings { + static String repeat(String input, int size) { + StringBuilder sb = new StringBuilder(input.length() * size); + for (int i = 0; i < size; i++) + sb.append(input); + String s = sb.toString(); + return s; + } +} |