summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2016-01-20 09:32:19 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2016-01-20 09:45:48 +0900
commitaca07fac464834611bab83b91e828308838f361c (patch)
treed2075304ea161f9a02e4f874b67ca7db8501499c /org.eclipse.jgit.test
parent2ccea7f05a0f3e783f6a8fa3f07cc5f1001bc950 (diff)
parent4b93de43bafd419b973ebf242e4ca1dd3b3b87d1 (diff)
downloadjgit-aca07fac464834611bab83b91e828308838f361c.tar.gz
jgit-aca07fac464834611bab83b91e828308838f361c.zip
Merge branch 'stable-4.2'
* stable-4.2: CheckoutCommandTest: Create Git instances in try-with-resource BranchCommandTest: Create Git instances in try-with-resource CheckoutTest: Create Git instances in try-with-resource BranchTest: Create Git instances in try-with-resource URIishTest: Use @Test annotation's `expected` argument Suppress "The allocated object is never used" warning in tests Add $NON-NLS to suppress "Non-externalized string literal" warnings Don't use deprecated constructors of CmdLineException Prepare 4.2.0-SNAPSHOT builds Remove org.eclipse.jgit.updatesite project from tools/version.sh RevParse: Remove superfluous semicolon RefUpdateTest: Use try-with-resource for auto-closable types RefUpdateTest: Add null check to prevent potential NPE CommitCommand: Remove redundant null check JGit v4.2.0.201512141825-rc1 Change-Id: I2179859289b2f2e3d0b7c6d02ef7e7890c467f7b Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java66
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java97
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java25
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java48
9 files changed, 119 insertions, 128 deletions
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 910a645e2b..2fe40b99ed 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
@@ -104,37 +104,38 @@ public class BranchCommandTest extends RepositoryTestCase {
private Git setUpRepoWithRemote() throws Exception {
Repository remoteRepository = createWorkRepository();
- Git remoteGit = new Git(remoteRepository);
- // commit something
- writeTrashFile("Test.txt", "Hello world");
- remoteGit.add().addFilepattern("Test.txt").call();
- initialCommit = remoteGit.commit().setMessage("Initial commit").call();
- writeTrashFile("Test.txt", "Some change");
- remoteGit.add().addFilepattern("Test.txt").call();
- secondCommit = remoteGit.commit().setMessage("Second commit").call();
- // create a master branch
- RefUpdate rup = remoteRepository.updateRef("refs/heads/master");
- rup.setNewObjectId(initialCommit.getId());
- rup.forceUpdate();
-
- Repository localRepository = createWorkRepository();
- Git localGit = new Git(localRepository);
- StoredConfig config = localRepository.getConfig();
- RemoteConfig rc = new RemoteConfig(config, "origin");
- rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath()));
- rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
- rc.update(config);
- config.save();
- FetchResult res = localGit.fetch().setRemote("origin").call();
- assertFalse(res.getTrackingRefUpdates().isEmpty());
- rup = localRepository.updateRef("refs/heads/master");
- rup.setNewObjectId(initialCommit.getId());
- rup.forceUpdate();
- rup = localRepository.updateRef(Constants.HEAD);
- rup.link("refs/heads/master");
- rup.setNewObjectId(initialCommit.getId());
- rup.update();
- return localGit;
+ try (Git remoteGit = new Git(remoteRepository)) {
+ // commit something
+ writeTrashFile("Test.txt", "Hello world");
+ remoteGit.add().addFilepattern("Test.txt").call();
+ initialCommit = remoteGit.commit().setMessage("Initial commit").call();
+ writeTrashFile("Test.txt", "Some change");
+ remoteGit.add().addFilepattern("Test.txt").call();
+ secondCommit = remoteGit.commit().setMessage("Second commit").call();
+ // create a master branch
+ RefUpdate rup = remoteRepository.updateRef("refs/heads/master");
+ rup.setNewObjectId(initialCommit.getId());
+ rup.forceUpdate();
+
+ Repository localRepository = createWorkRepository();
+ Git localGit = new Git(localRepository);
+ StoredConfig config = localRepository.getConfig();
+ RemoteConfig rc = new RemoteConfig(config, "origin");
+ rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath()));
+ rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
+ rc.update(config);
+ config.save();
+ FetchResult res = localGit.fetch().setRemote("origin").call();
+ assertFalse(res.getTrackingRefUpdates().isEmpty());
+ rup = localRepository.updateRef("refs/heads/master");
+ rup.setNewObjectId(initialCommit.getId());
+ rup.forceUpdate();
+ rup = localRepository.updateRef(Constants.HEAD);
+ rup.link("refs/heads/master");
+ rup.setNewObjectId(initialCommit.getId());
+ rup.update();
+ return localGit;
+ }
}
@Test
@@ -192,8 +193,7 @@ public class BranchCommandTest extends RepositoryTestCase {
@Test
public void testListAllBranchesShouldNotDie() throws Exception {
- Git git = setUpRepoWithRemote();
- git.branchList().setListMode(ListMode.ALL).call();
+ setUpRepoWithRemote().branchList().setListMode(ListMode.ALL).call();
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
index 4bfb128cbc..362d7ac9c9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
@@ -417,20 +417,20 @@ public class CheckoutCommandTest extends RepositoryTestCase {
InvalidRemoteException, TransportException {
// create second repository
Repository db2 = createWorkRepository();
- Git git2 = new Git(db2);
-
- // setup the second repository to fetch from the first repository
- final StoredConfig config = db2.getConfig();
- RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
- URIish uri = new URIish(db.getDirectory().toURI().toURL());
- remoteConfig.addURI(uri);
- remoteConfig.update(config);
- config.save();
-
- // fetch from first repository
- RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
- git2.fetch().setRemote("origin").setRefSpecs(spec).call();
- return db2;
+ try (Git git2 = new Git(db2)) {
+ // setup the second repository to fetch from the first repository
+ final StoredConfig config = db2.getConfig();
+ RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
+ URIish uri = new URIish(db.getDirectory().toURI().toURL());
+ remoteConfig.addURI(uri);
+ remoteConfig.update(config);
+ config.save();
+
+ // fetch from first repository
+ RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
+ git2.fetch().setRemote("origin").setRefSpecs(spec).call();
+ return db2;
+ }
}
private CheckoutCommand newOrphanBranchCommand() {
@@ -639,40 +639,41 @@ public class CheckoutCommandTest extends RepositoryTestCase {
File clean_filter = writeTempFile("sed s/V1/@version/g -");
File smudge_filter = writeTempFile("sed s/@version/V1/g -");
- Git git = new Git(db);
- StoredConfig config = git.getRepository().getConfig();
- config.setString("filter", "tstFilter", "smudge",
- "sh " + slashify(smudge_filter.getPath()));
- config.setString("filter", "tstFilter", "clean",
- "sh " + slashify(clean_filter.getPath()));
- config.save();
- writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
- git.add().addFilepattern(".gitattributes").call();
- git.commit().setMessage("add attributes").call();
-
- writeTrashFile("filterTest.txt", "hello world, V1");
- git.add().addFilepattern("filterTest.txt").call();
- git.commit().setMessage("add filterText.txt").call();
- assertEquals(
- "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
- indexState(CONTENT));
-
- git.checkout().setCreateBranch(true).setName("test2").call();
- writeTrashFile("filterTest.txt", "bon giorno world, V1");
- git.add().addFilepattern("filterTest.txt").call();
- git.commit().setMessage("modified filterText.txt").call();
-
- assertTrue(git.status().call().isClean());
- assertEquals(
- "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:bon giorno world, @version]",
- indexState(CONTENT));
-
- git.checkout().setName("refs/heads/test").call();
- assertTrue(git.status().call().isClean());
- assertEquals(
- "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
- indexState(CONTENT));
- assertEquals("hello world, V1", read("filterTest.txt"));
+ try (Git git2 = new Git(db)) {
+ StoredConfig config = git.getRepository().getConfig();
+ config.setString("filter", "tstFilter", "smudge",
+ "sh " + slashify(smudge_filter.getPath()));
+ config.setString("filter", "tstFilter", "clean",
+ "sh " + slashify(clean_filter.getPath()));
+ config.save();
+ writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
+ git2.add().addFilepattern(".gitattributes").call();
+ git2.commit().setMessage("add attributes").call();
+
+ writeTrashFile("filterTest.txt", "hello world, V1");
+ git2.add().addFilepattern("filterTest.txt").call();
+ git2.commit().setMessage("add filterText.txt").call();
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
+ indexState(CONTENT));
+
+ git2.checkout().setCreateBranch(true).setName("test2").call();
+ writeTrashFile("filterTest.txt", "bon giorno world, V1");
+ git2.add().addFilepattern("filterTest.txt").call();
+ git2.commit().setMessage("modified filterText.txt").call();
+
+ assertTrue(git2.status().call().isClean());
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:bon giorno world, @version]",
+ indexState(CONTENT));
+
+ git2.checkout().setName("refs/heads/test").call();
+ assertTrue(git2.status().call().isClean());
+ assertEquals(
+ "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
+ indexState(CONTENT));
+ assertEquals("hello world, V1", read("filterTest.txt"));
+ }
}
private File writeTempFile(String body) throws IOException {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
index dc7181aece..05fa007904 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
@@ -69,6 +69,7 @@ public class DirCacheEntryTest {
assertFalse(isValidPath("a\u0000b"));
}
+ @SuppressWarnings("unused")
private static boolean isValidPath(String path) {
try {
new DirCacheEntry(path);
@@ -78,6 +79,7 @@ public class DirCacheEntryTest {
}
}
+ @SuppressWarnings("unused")
@Test
public void testCreate_ByStringPath() {
assertEquals("a", new DirCacheEntry("a").getPathString());
@@ -91,6 +93,7 @@ public class DirCacheEntryTest {
}
}
+ @SuppressWarnings("unused")
@Test
public void testCreate_ByStringPathAndStage() {
DirCacheEntry e;
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 6c8ee737d2..dca356434b 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
@@ -72,6 +72,7 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
.findGitDir(d).getGitDir());
}
+ @SuppressWarnings("unused")
@Test
public void emptyRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository();
@@ -83,6 +84,7 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
new FileRepository(r.getDirectory());
}
+ @SuppressWarnings("unused")
@Test
public void invalidRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository();
@@ -99,6 +101,7 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
}
}
+ @SuppressWarnings("unused")
@Test
public void unknownRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
index 8744ed1bd6..48434189e4 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
@@ -558,13 +558,15 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
assertEquals(ppid, db.resolve("refs/heads/master"));
// real test
- RevCommit old = new RevWalk(db).parseCommit(ppid);
- RefUpdate updateRef2 = db.updateRef("refs/heads/master");
- updateRef2.setExpectedOldObjectId(old);
- updateRef2.setNewObjectId(pid);
- Result update2 = updateRef2.update();
- assertEquals(Result.FAST_FORWARD, update2);
- assertEquals(pid, db.resolve("refs/heads/master"));
+ try (RevWalk rw = new RevWalk(db)) {
+ RevCommit old = rw.parseCommit(ppid);
+ RefUpdate updateRef2 = db.updateRef("refs/heads/master");
+ updateRef2.setExpectedOldObjectId(old);
+ updateRef2.setNewObjectId(pid);
+ Result update2 = updateRef2.update();
+ assertEquals(Result.FAST_FORWARD, update2);
+ assertEquals(pid, db.resolve("refs/heads/master"));
+ }
}
/**
@@ -707,9 +709,10 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// Create new Repository instance, to reread caches and make sure our
// assumptions are persistent.
- Repository ndb = new FileRepository(db.getDirectory());
- assertEquals(rb2, ndb.resolve("refs/heads/new/name"));
- assertNull(ndb.resolve("refs/heads/b"));
+ try (Repository ndb = new FileRepository(db.getDirectory())) {
+ assertEquals(rb2, ndb.resolve("refs/heads/new/name"));
+ assertNull(ndb.resolve("refs/heads/b"));
+ }
}
public void tryRenameWhenLocked(String toLock, String fromName,
@@ -751,7 +754,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
assertNull(db.resolve(toName));
assertEquals(oldFromLog.toString(), db.getReflogReader(fromName)
.getReverseEntries().toString());
- if (oldHeadId != null)
+ if (oldHeadId != null && oldHeadLog != null)
assertEquals(oldHeadLog.toString(), db.getReflogReader(
Constants.HEAD).getReverseEntries().toString());
} finally {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
index a100ff357f..f4d655f86b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
@@ -362,6 +362,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
assertNotSame(db.getConfig(), db2.getConfig());
}
+ @SuppressWarnings("unused")
@Test
public void test008_FailOnWrongVersion() throws IOException {
final File cfg = new File(db.getDirectory(), Constants.CONFIG);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java
index 315c495606..1515a07ac4 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java
@@ -75,11 +75,13 @@ public class T0001_PersonIdentTest {
p.toExternalString());
}
+ @SuppressWarnings("unused")
@Test(expected = IllegalArgumentException.class)
public void nullForNameShouldThrowIllegalArgumentException() {
new PersonIdent(null, "author@example.com");
}
+ @SuppressWarnings("unused")
@Test(expected = IllegalArgumentException.class)
public void nullForEmailShouldThrowIllegalArgumentException() {
new PersonIdent("A U Thor", null);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
index e9ae1909ea..3661677cd9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
@@ -195,6 +195,7 @@ public class SideBandOutputStreamTest {
assertEquals(1, flushCnt[0]);
}
+ @SuppressWarnings("unused")
@Test
public void testConstructor_RejectsBadChannel() {
try {
@@ -220,6 +221,7 @@ public class SideBandOutputStreamTest {
}
}
+ @SuppressWarnings("unused")
@Test
public void testConstructor_RejectsBadBufferSize() {
try {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
index 5e4ba35079..e55d373347 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
@@ -51,7 +51,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
@@ -64,24 +63,16 @@ public class URIishTest {
private static final String GIT_SCHEME = "git://";
- @Test
+ @SuppressWarnings("unused")
+ @Test(expected = URISyntaxException.class)
public void shouldRaiseErrorOnEmptyURI() throws Exception {
- try {
- new URIish("");
- fail("expecting an exception");
- } catch (URISyntaxException e) {
- // expected
- }
+ new URIish("");
}
- @Test
+ @SuppressWarnings("unused")
+ @Test(expected = URISyntaxException.class)
public void shouldRaiseErrorOnNullURI() throws Exception {
- try {
- new URIish((String) null);
- fail("expecting an exception");
- } catch (URISyntaxException e) {
- // expected
- }
+ new URIish((String) null);
}
@Test
@@ -634,34 +625,19 @@ public class URIishTest {
assertEquals(u, new URIish(str));
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testGetNullHumanishName() {
- try {
- new URIish().getHumanishName();
- fail("path must be not null");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ new URIish().getHumanishName();
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testGetEmptyHumanishName() throws URISyntaxException {
- try {
- new URIish(GIT_SCHEME).getHumanishName();
- fail("empty path is useless");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ new URIish(GIT_SCHEME).getHumanishName();
}
- @Test
+ @Test(expected = IllegalArgumentException.class)
public void testGetAbsEmptyHumanishName() {
- try {
- new URIish().getHumanishName();
- fail("empty path is useless");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ new URIish().getHumanishName();
}
@Test