]> source.dussan.org Git - jgit.git/commitdiff
Don't throw away the stack trace when tests fail 49/4549/1
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Sat, 5 Nov 2011 15:52:24 +0000 (16:52 +0100)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Sun, 6 Nov 2011 09:00:06 +0000 (10:00 +0100)
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

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

index 6e9f851793c31af9bb0bb2ab520dcbd0a1066892..7d75a6cda956664238dfd40c5983edaaac31ed25 100644 (file)
@@ -103,38 +103,25 @@ public class CheckoutCommandTest extends RepositoryTestCase {
        }
 
        @Test
-       public void testSimpleCheckout() {
-               try {
-                       git.checkout().setName("test").call();
-               } catch (Exception e) {
-                       fail(e.getMessage());
-               }
+       public void testSimpleCheckout() throws Exception {
+               git.checkout().setName("test").call();
        }
 
        @Test
-       public void testCheckout() {
-               try {
-                       git.checkout().setName("test").call();
-                       assertEquals("[Test.txt, mode:100644, content:Some change]",
-                                       indexState(CONTENT));
-                       Ref result = git.checkout().setName("master").call();
-                       assertEquals("[Test.txt, mode:100644, content:Hello world]",
-                                       indexState(CONTENT));
-                       assertEquals("refs/heads/master", result.getName());
-                       assertEquals("refs/heads/master", git.getRepository()
-                                       .getFullBranch());
-               } catch (Exception e) {
-                       fail(e.getMessage());
-               }
+       public void testCheckout() throws Exception {
+               git.checkout().setName("test").call();
+               assertEquals("[Test.txt, mode:100644, content:Some change]",
+                               indexState(CONTENT));
+               Ref result = git.checkout().setName("master").call();
+               assertEquals("[Test.txt, mode:100644, content:Hello world]",
+                               indexState(CONTENT));
+               assertEquals("refs/heads/master", result.getName());
+               assertEquals("refs/heads/master", git.getRepository().getFullBranch());
        }
 
        @Test
-       public void testCreateBranchOnCheckout() throws IOException {
-               try {
-                       git.checkout().setCreateBranch(true).setName("test2").call();
-               } catch (Exception e) {
-                       fail(e.getMessage());
-               }
+       public void testCreateBranchOnCheckout() throws Exception {
+               git.checkout().setCreateBranch(true).setName("test2").call();
                assertNotNull(db.getRef("test2"));
        }
 
@@ -200,45 +187,36 @@ public class CheckoutCommandTest extends RepositoryTestCase {
        }
 
        @Test
-       public void testCheckoutCommit() {
-               try {
-                       Ref result = git.checkout().setName(initialCommit.name()).call();
-                       assertEquals("[Test.txt, mode:100644, content:Hello world]",
-                                       indexState(CONTENT));
-                       assertNull(result);
-                       assertEquals(initialCommit.name(), git.getRepository()
-                                       .getFullBranch());
-               } catch (Exception e) {
-                       fail(e.getMessage());
-               }
+       public void testCheckoutCommit() throws Exception {
+               Ref result = git.checkout().setName(initialCommit.name()).call();
+               assertEquals("[Test.txt, mode:100644, content:Hello world]",
+                               indexState(CONTENT));
+               assertNull(result);
+               assertEquals(initialCommit.name(), git.getRepository().getFullBranch());
        }
 
        @Test
-       public void testCheckoutRemoteTrackingWithoutLocalBranch() {
-               try {
-                       // 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();
-                       // checkout remote tracking branch in second repository
-                       // (no local branches exist yet in second repository)
-                       git2.checkout().setName("remotes/origin/test").call();
-                       assertEquals("[Test.txt, mode:100644, content:Some change]",
-                                       indexState(db2, CONTENT));
-               } catch (Exception e) {
-                       fail(e.getMessage());
-               }
+       public void testCheckoutRemoteTrackingWithoutLocalBranch() throws Exception {
+               // 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();
+               // checkout remote tracking branch in second repository
+               // (no local branches exist yet in second repository)
+               git2.checkout().setName("remotes/origin/test").call();
+               assertEquals("[Test.txt, mode:100644, content:Some change]",
+                               indexState(db2, CONTENT));
        }
 
        @Test
index 7d3a55e2afccede2dfdde1ffc726716a9dad1f46..ac563b061831d7669cc195bc48f1b6881287a097 100644 (file)
@@ -44,7 +44,6 @@ package org.eclipse.jgit.api;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.util.Collection;
@@ -79,69 +78,54 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
        }
 
        @Test
-       public void testLsRemote() {
-               try {
-                       File directory = createTempDirectory("testRepository");
-                       CloneCommand command = Git.cloneRepository();
-                       command.setDirectory(directory);
-                       command.setURI("file://"
-                                       + git.getRepository().getWorkTree().getPath());
-                       command.setCloneAllBranches(true);
-                       Git git2 = command.call();
-                       addRepoToClose(git2.getRepository());
-
-
-                       LsRemoteCommand lsRemoteCommand = git2.lsRemote();
-                       Collection<Ref> refs = lsRemoteCommand.call();
-                       assertNotNull(refs);
-                       assertEquals(6, refs.size());
-               } catch (Exception e) {
-                       fail(e.getMessage());
-               }
+       public void testLsRemote() throws Exception {
+               File directory = createTempDirectory("testRepository");
+               CloneCommand command = Git.cloneRepository();
+               command.setDirectory(directory);
+               command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+               command.setCloneAllBranches(true);
+               Git git2 = command.call();
+               addRepoToClose(git2.getRepository());
+
+
+               LsRemoteCommand lsRemoteCommand = git2.lsRemote();
+               Collection<Ref> refs = lsRemoteCommand.call();
+               assertNotNull(refs);
+               assertEquals(6, refs.size());
        }
 
        @Test
-       public void testLsRemoteWithTags() {
-               try {
-                       File directory = createTempDirectory("testRepository");
-                       CloneCommand command = Git.cloneRepository();
-                       command.setDirectory(directory);
-                       command.setURI("file://"
-                                       + git.getRepository().getWorkTree().getPath());
-                       command.setCloneAllBranches(true);
-                       Git git2 = command.call();
-                       addRepoToClose(git2.getRepository());
-
-                       LsRemoteCommand lsRemoteCommand = git2.lsRemote();
-                       lsRemoteCommand.setTags(true);
-                       Collection<Ref> refs = lsRemoteCommand.call();
-                       assertNotNull(refs);
-                       assertEquals(3, refs.size());
-               } catch (Exception e) {
-                       fail(e.getMessage());
-               }
+       public void testLsRemoteWithTags() throws Exception {
+               File directory = createTempDirectory("testRepository");
+               CloneCommand command = Git.cloneRepository();
+               command.setDirectory(directory);
+               command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+               command.setCloneAllBranches(true);
+               Git git2 = command.call();
+               addRepoToClose(git2.getRepository());
+
+               LsRemoteCommand lsRemoteCommand = git2.lsRemote();
+               lsRemoteCommand.setTags(true);
+               Collection<Ref> refs = lsRemoteCommand.call();
+               assertNotNull(refs);
+               assertEquals(3, refs.size());
        }
 
        @Test
-       public void testLsRemoteWithHeads() {
-               try {
-                       File directory = createTempDirectory("testRepository");
-                       CloneCommand command = Git.cloneRepository();
-                       command.setDirectory(directory);
-                       command.setURI("file://"
-                                       + git.getRepository().getWorkTree().getPath());
-                       command.setCloneAllBranches(true);
-                       Git git2 = command.call();
-                       addRepoToClose(git2.getRepository());
-
-                       LsRemoteCommand lsRemoteCommand = git2.lsRemote();
-                       lsRemoteCommand.setHeads(true);
-                       Collection<Ref> refs = lsRemoteCommand.call();
-                       assertNotNull(refs);
-                       assertEquals(2, refs.size());
-               } catch (Exception e) {
-                       fail(e.getMessage());
-               }
+       public void testLsRemoteWithHeads() throws Exception {
+               File directory = createTempDirectory("testRepository");
+               CloneCommand command = Git.cloneRepository();
+               command.setDirectory(directory);
+               command.setURI("file://" + git.getRepository().getWorkTree().getPath());
+               command.setCloneAllBranches(true);
+               Git git2 = command.call();
+               addRepoToClose(git2.getRepository());
+
+               LsRemoteCommand lsRemoteCommand = git2.lsRemote();
+               lsRemoteCommand.setHeads(true);
+               Collection<Ref> refs = lsRemoteCommand.call();
+               assertNotNull(refs);
+               assertEquals(2, refs.size());
        }
 
 }