From 7e1b2466e3928f3b2863912ef83b316ed39082db Mon Sep 17 00:00:00 2001 From: Stefan Lay Date: Wed, 6 Jul 2011 13:36:57 +0200 Subject: [PATCH] Do not catch Exception in test cases Exception handling is already done by JUnit. Change-Id: Ia25d768c311d384d728f281aced92f598e5e2041 Signed-off-by: Stefan Lay --- .../eclipse/jgit/api/CloneCommandTest.java | 227 ++++++++---------- .../org/eclipse/jgit/api/InitCommandTest.java | 41 ++-- 2 files changed, 115 insertions(+), 153 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index 2e3345756d..ca52607669 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.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.io.IOException; @@ -93,139 +92,111 @@ public class CloneCommandTest extends RepositoryTestCase { } @Test - public void testCloneRepository() { - try { - File directory = createTempDirectory("testCloneRepository"); - CloneCommand command = Git.cloneRepository(); - command.setDirectory(directory); - command.setURI("file://" - + git.getRepository().getWorkTree().getPath()); - Git git2 = command.call(); - addRepoToClose(git2.getRepository()); - assertNotNull(git2); - ObjectId id = git2.getRepository().resolve("tag-for-blob"); - assertNotNull(id); - assertEquals(git2.getRepository().getFullBranch(), - "refs/heads/test"); - assertEquals( - "origin", - git2.getRepository() - .getConfig() - .getString(ConfigConstants.CONFIG_BRANCH_SECTION, - "test", ConfigConstants.CONFIG_KEY_REMOTE)); - assertEquals( - "refs/heads/test", - git2.getRepository() - .getConfig() - .getString(ConfigConstants.CONFIG_BRANCH_SECTION, - "test", ConfigConstants.CONFIG_KEY_MERGE)); - assertEquals(2, git2.branchList().setListMode(ListMode.REMOTE) - .call().size()); - } catch (Exception e) { - fail(e.getMessage()); - } + public void testCloneRepository() throws IOException { + File directory = createTempDirectory("testCloneRepository"); + CloneCommand command = Git.cloneRepository(); + command.setDirectory(directory); + command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertNotNull(git2); + ObjectId id = git2.getRepository().resolve("tag-for-blob"); + assertNotNull(id); + assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test"); + assertEquals( + "origin", + git2.getRepository() + .getConfig() + .getString(ConfigConstants.CONFIG_BRANCH_SECTION, + "test", ConfigConstants.CONFIG_KEY_REMOTE)); + assertEquals( + "refs/heads/test", + git2.getRepository() + .getConfig() + .getString(ConfigConstants.CONFIG_BRANCH_SECTION, + "test", ConfigConstants.CONFIG_KEY_MERGE)); + assertEquals(2, git2.branchList().setListMode(ListMode.REMOTE).call() + .size()); } @Test - public void testCloneRepositoryWithBranch() { - try { - File directory = createTempDirectory("testCloneRepositoryWithBranch"); - CloneCommand command = Git.cloneRepository(); - command.setBranch("refs/heads/master"); - command.setDirectory(directory); - command.setURI("file://" - + git.getRepository().getWorkTree().getPath()); - Git git2 = command.call(); - addRepoToClose(git2.getRepository()); - - assertNotNull(git2); - assertEquals(git2.getRepository().getFullBranch(), - "refs/heads/master"); - assertEquals( - "refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test", - allRefNames(git2.branchList().setListMode(ListMode.ALL) - .call())); - - // Same thing, but now without checkout - directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); - command = Git.cloneRepository(); - command.setBranch("refs/heads/master"); - command.setDirectory(directory); - command.setURI("file://" - + git.getRepository().getWorkTree().getPath()); - command.setNoCheckout(true); - git2 = command.call(); - addRepoToClose(git2.getRepository()); - - assertNotNull(git2); - assertEquals(git2.getRepository().getFullBranch(), - "refs/heads/master"); - assertEquals( - "refs/remotes/origin/master, refs/remotes/origin/test", - allRefNames(git2.branchList().setListMode(ListMode.ALL) - .call())); - - // Same thing, but now test with bare repo - directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); - command = Git.cloneRepository(); - command.setBranch("refs/heads/master"); - command.setDirectory(directory); - command.setURI("file://" - + git.getRepository().getWorkTree().getPath()); - command.setBare(true); - git2 = command.call(); - addRepoToClose(git2.getRepository()); - - assertNotNull(git2); - assertEquals(git2.getRepository().getFullBranch(), - "refs/heads/master"); - assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2 - .branchList().setListMode(ListMode.ALL).call())); - } catch (Exception e) { - fail(e.getMessage()); - } + public void testCloneRepositoryWithBranch() throws IOException { + File directory = createTempDirectory("testCloneRepositoryWithBranch"); + CloneCommand command = Git.cloneRepository(); + command.setBranch("refs/heads/master"); + command.setDirectory(directory); + command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); + assertEquals( + "refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test", + allRefNames(git2.branchList().setListMode(ListMode.ALL).call())); + + // Same thing, but now without checkout + directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); + command = Git.cloneRepository(); + command.setBranch("refs/heads/master"); + command.setDirectory(directory); + command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setNoCheckout(true); + git2 = command.call(); + addRepoToClose(git2.getRepository()); + + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); + assertEquals("refs/remotes/origin/master, refs/remotes/origin/test", + allRefNames(git2.branchList().setListMode(ListMode.ALL).call())); + + // Same thing, but now test with bare repo + directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); + command = Git.cloneRepository(); + command.setBranch("refs/heads/master"); + command.setDirectory(directory); + command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setBare(true); + git2 = command.call(); + addRepoToClose(git2.getRepository()); + + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); + assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2 + .branchList().setListMode(ListMode.ALL).call())); } @Test - public void testCloneRepositoryOnlyOneBranch() { - try { - File directory = createTempDirectory("testCloneRepositoryWithBranch"); - CloneCommand command = Git.cloneRepository(); - command.setBranch("refs/heads/master"); - command.setBranchesToClone(Collections - .singletonList("refs/heads/master")); - command.setDirectory(directory); - command.setURI("file://" - + git.getRepository().getWorkTree().getPath()); - Git git2 = command.call(); - addRepoToClose(git2.getRepository()); - assertNotNull(git2); - assertEquals(git2.getRepository().getFullBranch(), - "refs/heads/master"); - assertEquals("refs/remotes/origin/master", - allRefNames(git2.branchList() - .setListMode(ListMode.REMOTE).call())); - - // Same thing, but now test with bare repo - directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); - command = Git.cloneRepository(); - command.setBranch("refs/heads/master"); - command.setBranchesToClone(Collections - .singletonList("refs/heads/master")); - command.setDirectory(directory); - command.setURI("file://" - + git.getRepository().getWorkTree().getPath()); - command.setBare(true); - git2 = command.call(); - addRepoToClose(git2.getRepository()); - assertNotNull(git2); - assertEquals(git2.getRepository().getFullBranch(), - "refs/heads/master"); - assertEquals("refs/heads/master", allRefNames(git2 - .branchList().setListMode(ListMode.ALL).call())); - } catch (Exception e) { - fail(e.getMessage()); - } + public void testCloneRepositoryOnlyOneBranch() throws IOException { + File directory = createTempDirectory("testCloneRepositoryWithBranch"); + CloneCommand command = Git.cloneRepository(); + command.setBranch("refs/heads/master"); + command.setBranchesToClone(Collections + .singletonList("refs/heads/master")); + command.setDirectory(directory); + command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + Git git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); + assertEquals("refs/remotes/origin/master", allRefNames(git2 + .branchList().setListMode(ListMode.REMOTE).call())); + + // Same thing, but now test with bare repo + directory = createTempDirectory("testCloneRepositoryWithBranch_bare"); + command = Git.cloneRepository(); + command.setBranch("refs/heads/master"); + command.setBranchesToClone(Collections + .singletonList("refs/heads/master")); + command.setDirectory(directory); + command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setBare(true); + git2 = command.call(); + addRepoToClose(git2.getRepository()); + assertNotNull(git2); + assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master"); + assertEquals("refs/heads/master", allRefNames(git2.branchList() + .setListMode(ListMode.ALL).call())); } public static String allRefNames(List refs) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java index 28c54c269f..7f47295c3f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java @@ -44,7 +44,6 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; @@ -64,33 +63,25 @@ public class InitCommandTest extends RepositoryTestCase { } @Test - public void testInitRepository() { - try { - File directory = createTempDirectory("testInitRepository"); - InitCommand command = new InitCommand(); - command.setDirectory(directory); - Repository repository = command.call().getRepository(); - addRepoToClose(repository); - assertNotNull(repository); - } catch (Exception e) { - fail(e.getMessage()); - } + public void testInitRepository() throws IOException { + File directory = createTempDirectory("testInitRepository"); + InitCommand command = new InitCommand(); + command.setDirectory(directory); + Repository repository = command.call().getRepository(); + addRepoToClose(repository); + assertNotNull(repository); } @Test - public void testInitBareRepository() { - try { - File directory = createTempDirectory("testInitBareRepository"); - InitCommand command = new InitCommand(); - command.setDirectory(directory); - command.setBare(true); - Repository repository = command.call().getRepository(); - addRepoToClose(repository); - assertNotNull(repository); - assertTrue(repository.isBare()); - } catch (Exception e) { - fail(e.getMessage()); - } + public void testInitBareRepository() throws IOException { + File directory = createTempDirectory("testInitBareRepository"); + InitCommand command = new InitCommand(); + command.setDirectory(directory); + command.setBare(true); + Repository repository = command.call().getRepository(); + addRepoToClose(repository); + assertNotNull(repository); + assertTrue(repository.isBare()); } public static File createTempDirectory(String name) throws IOException { -- 2.39.5