From 790ddb2983bce01d2d0b5b1049d5576fa0c136a8 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sat, 5 Nov 2011 16:52:24 +0100 Subject: [PATCH] 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 --- .../eclipse/jgit/api/CheckoutCommandTest.java | 102 +++++++----------- .../eclipse/jgit/api/LsRemoteCommandTest.java | 100 ++++++++--------- 2 files changed, 82 insertions(+), 120 deletions(-) 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 6e9f85179..7d75a6cda 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 @@ -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 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 7d3a55e2a..ac563b061 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 @@ -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 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 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 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 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 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 refs = lsRemoteCommand.call(); + assertNotNull(refs); + assertEquals(2, refs.size()); } }