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. 36
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
  2. 28
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java

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

@ -103,17 +103,12 @@ 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));
@ -121,20 +116,12 @@ public class CheckoutCommandTest extends RepositoryTestCase {
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() assertEquals("refs/heads/master", git.getRepository().getFullBranch());
.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,22 +187,16 @@ 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() assertEquals(initialCommit.name(), git.getRepository().getFullBranch());
.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);
@ -236,9 +217,6 @@ public class CheckoutCommandTest extends RepositoryTestCase {
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

28
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,13 +78,11 @@ 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://" command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+ git.getRepository().getWorkTree().getPath());
command.setCloneAllBranches(true); command.setCloneAllBranches(true);
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
@ -95,19 +92,14 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
Collection<Ref> refs = lsRemoteCommand.call(); Collection<Ref> refs = lsRemoteCommand.call();
assertNotNull(refs); assertNotNull(refs);
assertEquals(6, refs.size()); 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://" command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+ git.getRepository().getWorkTree().getPath());
command.setCloneAllBranches(true); command.setCloneAllBranches(true);
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
@ -117,19 +109,14 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
Collection<Ref> refs = lsRemoteCommand.call(); Collection<Ref> refs = lsRemoteCommand.call();
assertNotNull(refs); assertNotNull(refs);
assertEquals(3, refs.size()); 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://" command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+ git.getRepository().getWorkTree().getPath());
command.setCloneAllBranches(true); command.setCloneAllBranches(true);
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
@ -139,9 +126,6 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
Collection<Ref> refs = lsRemoteCommand.call(); Collection<Ref> refs = lsRemoteCommand.call();
assertNotNull(refs); assertNotNull(refs);
assertEquals(2, refs.size()); assertEquals(2, refs.size());
} catch (Exception e) {
fail(e.getMessage());
}
} }
} }

Loading…
Cancel
Save