Bläddra i källkod

Do not catch Exception in test cases

Exception handling is already done by JUnit.

Change-Id: Ia25d768c311d384d728f281aced92f598e5e2041
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
tags/v1.1.0.201109011030-rc2
Stefan Lay 13 år sedan
förälder
incheckning
7e1b2466e3

+ 99
- 128
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java Visa fil

@@ -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<Ref> refs) {

+ 16
- 25
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java Visa fil

@@ -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 {

Laddar…
Avbryt
Spara