Browse Source

Don't throw away the stack trace when tests fail

Most unexpected exceptions are completely useless yielding message
like "null" or "3" or in the best cases something reasonable, but
still out of context.

Just declare the test as throwing an exception. That will retain
the full stack trace leading to the point of failure without using
a debugger or changing the code.

Change-Id: Id2454d328d1aa665606ae002de2c3805fe7baa8e
stable-1.2
Robin Rosenberg 13 years ago
parent
commit
790ddb2983
  1. 102
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
  2. 100
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java

102
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java

@ -103,38 +103,25 @@ public class CheckoutCommandTest extends RepositoryTestCase {
} }
@Test @Test
public void testSimpleCheckout() { public void testSimpleCheckout() throws Exception {
try { git.checkout().setName("test").call();
git.checkout().setName("test").call();
} catch (Exception e) {
fail(e.getMessage());
}
} }
@Test @Test
public void testCheckout() { public void testCheckout() throws Exception {
try { git.checkout().setName("test").call();
git.checkout().setName("test").call(); assertEquals("[Test.txt, mode:100644, content:Some change]",
assertEquals("[Test.txt, mode:100644, content:Some change]", indexState(CONTENT));
indexState(CONTENT)); Ref result = git.checkout().setName("master").call();
Ref result = git.checkout().setName("master").call(); assertEquals("[Test.txt, mode:100644, content:Hello world]",
assertEquals("[Test.txt, mode:100644, content:Hello world]", indexState(CONTENT));
indexState(CONTENT)); assertEquals("refs/heads/master", result.getName());
assertEquals("refs/heads/master", result.getName()); assertEquals("refs/heads/master", git.getRepository().getFullBranch());
assertEquals("refs/heads/master", git.getRepository()
.getFullBranch());
} catch (Exception e) {
fail(e.getMessage());
}
} }
@Test @Test
public void testCreateBranchOnCheckout() throws IOException { public void testCreateBranchOnCheckout() throws Exception {
try { git.checkout().setCreateBranch(true).setName("test2").call();
git.checkout().setCreateBranch(true).setName("test2").call();
} catch (Exception e) {
fail(e.getMessage());
}
assertNotNull(db.getRef("test2")); assertNotNull(db.getRef("test2"));
} }
@ -200,45 +187,36 @@ public class CheckoutCommandTest extends RepositoryTestCase {
} }
@Test @Test
public void testCheckoutCommit() { public void testCheckoutCommit() throws Exception {
try { Ref result = git.checkout().setName(initialCommit.name()).call();
Ref result = git.checkout().setName(initialCommit.name()).call(); assertEquals("[Test.txt, mode:100644, content:Hello world]",
assertEquals("[Test.txt, mode:100644, content:Hello world]", indexState(CONTENT));
indexState(CONTENT)); assertNull(result);
assertNull(result); assertEquals(initialCommit.name(), git.getRepository().getFullBranch());
assertEquals(initialCommit.name(), git.getRepository()
.getFullBranch());
} catch (Exception e) {
fail(e.getMessage());
}
} }
@Test @Test
public void testCheckoutRemoteTrackingWithoutLocalBranch() { public void testCheckoutRemoteTrackingWithoutLocalBranch() throws Exception {
try { // create second repository
// create second repository Repository db2 = createWorkRepository();
Repository db2 = createWorkRepository(); Git git2 = new Git(db2);
Git git2 = new Git(db2);
// setup the second repository to fetch from the first repository
// setup the second repository to fetch from the first repository final StoredConfig config = db2.getConfig();
final StoredConfig config = db2.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
RemoteConfig remoteConfig = new RemoteConfig(config, "origin"); URIish uri = new URIish(db.getDirectory().toURI().toURL());
URIish uri = new URIish(db.getDirectory().toURI().toURL()); remoteConfig.addURI(uri);
remoteConfig.addURI(uri); remoteConfig.update(config);
remoteConfig.update(config); config.save();
config.save();
// fetch from first repository
// fetch from first repository RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*"); git2.fetch().setRemote("origin").setRefSpecs(spec).call();
git2.fetch().setRemote("origin").setRefSpecs(spec).call(); // checkout remote tracking branch in second repository
// checkout remote tracking branch in second repository // (no local branches exist yet in second repository)
// (no local branches exist yet in second repository) git2.checkout().setName("remotes/origin/test").call();
git2.checkout().setName("remotes/origin/test").call(); assertEquals("[Test.txt, mode:100644, content:Some change]",
assertEquals("[Test.txt, mode:100644, content:Some change]", indexState(db2, CONTENT));
indexState(db2, CONTENT));
} catch (Exception e) {
fail(e.getMessage());
}
} }
@Test @Test

100
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java

@ -44,7 +44,6 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
@ -79,69 +78,54 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
} }
@Test @Test
public void testLsRemote() { public void testLsRemote() throws Exception {
try { File directory = createTempDirectory("testRepository");
File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository();
CloneCommand command = Git.cloneRepository(); command.setDirectory(directory);
command.setDirectory(directory); command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI("file://" command.setCloneAllBranches(true);
+ git.getRepository().getWorkTree().getPath()); Git git2 = command.call();
command.setCloneAllBranches(true); addRepoToClose(git2.getRepository());
Git git2 = command.call();
addRepoToClose(git2.getRepository());
LsRemoteCommand lsRemoteCommand = git2.lsRemote();
Collection<Ref> refs = lsRemoteCommand.call();
LsRemoteCommand lsRemoteCommand = git2.lsRemote(); assertNotNull(refs);
Collection<Ref> refs = lsRemoteCommand.call(); assertEquals(6, refs.size());
assertNotNull(refs);
assertEquals(6, refs.size());
} catch (Exception e) {
fail(e.getMessage());
}
} }
@Test @Test
public void testLsRemoteWithTags() { public void testLsRemoteWithTags() throws Exception {
try { File directory = createTempDirectory("testRepository");
File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository();
CloneCommand command = Git.cloneRepository(); command.setDirectory(directory);
command.setDirectory(directory); command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI("file://" command.setCloneAllBranches(true);
+ git.getRepository().getWorkTree().getPath()); Git git2 = command.call();
command.setCloneAllBranches(true); addRepoToClose(git2.getRepository());
Git git2 = command.call();
addRepoToClose(git2.getRepository()); LsRemoteCommand lsRemoteCommand = git2.lsRemote();
lsRemoteCommand.setTags(true);
LsRemoteCommand lsRemoteCommand = git2.lsRemote(); Collection<Ref> refs = lsRemoteCommand.call();
lsRemoteCommand.setTags(true); assertNotNull(refs);
Collection<Ref> refs = lsRemoteCommand.call(); assertEquals(3, refs.size());
assertNotNull(refs);
assertEquals(3, refs.size());
} catch (Exception e) {
fail(e.getMessage());
}
} }
@Test @Test
public void testLsRemoteWithHeads() { public void testLsRemoteWithHeads() throws Exception {
try { File directory = createTempDirectory("testRepository");
File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository();
CloneCommand command = Git.cloneRepository(); command.setDirectory(directory);
command.setDirectory(directory); command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI("file://" command.setCloneAllBranches(true);
+ git.getRepository().getWorkTree().getPath()); Git git2 = command.call();
command.setCloneAllBranches(true); addRepoToClose(git2.getRepository());
Git git2 = command.call();
addRepoToClose(git2.getRepository()); LsRemoteCommand lsRemoteCommand = git2.lsRemote();
lsRemoteCommand.setHeads(true);
LsRemoteCommand lsRemoteCommand = git2.lsRemote(); Collection<Ref> refs = lsRemoteCommand.call();
lsRemoteCommand.setHeads(true); assertNotNull(refs);
Collection<Ref> refs = lsRemoteCommand.call(); assertEquals(2, refs.size());
assertNotNull(refs);
assertEquals(2, refs.size());
} catch (Exception e) {
fail(e.getMessage());
}
} }
} }

Loading…
Cancel
Save