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>
This commit is contained in:
parent
9ea9537d7c
commit
7e1b2466e3
|
@ -44,7 +44,6 @@
|
||||||
|
|
||||||
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.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -93,20 +92,17 @@ public void setUp() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloneRepository() {
|
public void testCloneRepository() throws IOException {
|
||||||
try {
|
|
||||||
File directory = createTempDirectory("testCloneRepository");
|
File directory = createTempDirectory("testCloneRepository");
|
||||||
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());
|
|
||||||
Git git2 = command.call();
|
Git git2 = command.call();
|
||||||
addRepoToClose(git2.getRepository());
|
addRepoToClose(git2.getRepository());
|
||||||
assertNotNull(git2);
|
assertNotNull(git2);
|
||||||
ObjectId id = git2.getRepository().resolve("tag-for-blob");
|
ObjectId id = git2.getRepository().resolve("tag-for-blob");
|
||||||
assertNotNull(id);
|
assertNotNull(id);
|
||||||
assertEquals(git2.getRepository().getFullBranch(),
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test");
|
||||||
"refs/heads/test");
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"origin",
|
"origin",
|
||||||
git2.getRepository()
|
git2.getRepository()
|
||||||
|
@ -119,92 +115,72 @@ public void testCloneRepository() {
|
||||||
.getConfig()
|
.getConfig()
|
||||||
.getString(ConfigConstants.CONFIG_BRANCH_SECTION,
|
.getString(ConfigConstants.CONFIG_BRANCH_SECTION,
|
||||||
"test", ConfigConstants.CONFIG_KEY_MERGE));
|
"test", ConfigConstants.CONFIG_KEY_MERGE));
|
||||||
assertEquals(2, git2.branchList().setListMode(ListMode.REMOTE)
|
assertEquals(2, git2.branchList().setListMode(ListMode.REMOTE).call()
|
||||||
.call().size());
|
.size());
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloneRepositoryWithBranch() {
|
public void testCloneRepositoryWithBranch() throws IOException {
|
||||||
try {
|
|
||||||
File directory = createTempDirectory("testCloneRepositoryWithBranch");
|
File directory = createTempDirectory("testCloneRepositoryWithBranch");
|
||||||
CloneCommand command = Git.cloneRepository();
|
CloneCommand command = Git.cloneRepository();
|
||||||
command.setBranch("refs/heads/master");
|
command.setBranch("refs/heads/master");
|
||||||
command.setDirectory(directory);
|
command.setDirectory(directory);
|
||||||
command.setURI("file://"
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
|
||||||
+ git.getRepository().getWorkTree().getPath());
|
|
||||||
Git git2 = command.call();
|
Git git2 = command.call();
|
||||||
addRepoToClose(git2.getRepository());
|
addRepoToClose(git2.getRepository());
|
||||||
|
|
||||||
assertNotNull(git2);
|
assertNotNull(git2);
|
||||||
assertEquals(git2.getRepository().getFullBranch(),
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
|
||||||
"refs/heads/master");
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test",
|
"refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test",
|
||||||
allRefNames(git2.branchList().setListMode(ListMode.ALL)
|
allRefNames(git2.branchList().setListMode(ListMode.ALL).call()));
|
||||||
.call()));
|
|
||||||
|
|
||||||
// Same thing, but now without checkout
|
// Same thing, but now without checkout
|
||||||
directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
|
||||||
command = Git.cloneRepository();
|
command = Git.cloneRepository();
|
||||||
command.setBranch("refs/heads/master");
|
command.setBranch("refs/heads/master");
|
||||||
command.setDirectory(directory);
|
command.setDirectory(directory);
|
||||||
command.setURI("file://"
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
|
||||||
+ git.getRepository().getWorkTree().getPath());
|
|
||||||
command.setNoCheckout(true);
|
command.setNoCheckout(true);
|
||||||
git2 = command.call();
|
git2 = command.call();
|
||||||
addRepoToClose(git2.getRepository());
|
addRepoToClose(git2.getRepository());
|
||||||
|
|
||||||
assertNotNull(git2);
|
assertNotNull(git2);
|
||||||
assertEquals(git2.getRepository().getFullBranch(),
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
|
||||||
"refs/heads/master");
|
assertEquals("refs/remotes/origin/master, refs/remotes/origin/test",
|
||||||
assertEquals(
|
allRefNames(git2.branchList().setListMode(ListMode.ALL).call()));
|
||||||
"refs/remotes/origin/master, refs/remotes/origin/test",
|
|
||||||
allRefNames(git2.branchList().setListMode(ListMode.ALL)
|
|
||||||
.call()));
|
|
||||||
|
|
||||||
// Same thing, but now test with bare repo
|
// Same thing, but now test with bare repo
|
||||||
directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
|
||||||
command = Git.cloneRepository();
|
command = Git.cloneRepository();
|
||||||
command.setBranch("refs/heads/master");
|
command.setBranch("refs/heads/master");
|
||||||
command.setDirectory(directory);
|
command.setDirectory(directory);
|
||||||
command.setURI("file://"
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
|
||||||
+ git.getRepository().getWorkTree().getPath());
|
|
||||||
command.setBare(true);
|
command.setBare(true);
|
||||||
git2 = command.call();
|
git2 = command.call();
|
||||||
addRepoToClose(git2.getRepository());
|
addRepoToClose(git2.getRepository());
|
||||||
|
|
||||||
assertNotNull(git2);
|
assertNotNull(git2);
|
||||||
assertEquals(git2.getRepository().getFullBranch(),
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
|
||||||
"refs/heads/master");
|
|
||||||
assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2
|
assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2
|
||||||
.branchList().setListMode(ListMode.ALL).call()));
|
.branchList().setListMode(ListMode.ALL).call()));
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloneRepositoryOnlyOneBranch() {
|
public void testCloneRepositoryOnlyOneBranch() throws IOException {
|
||||||
try {
|
|
||||||
File directory = createTempDirectory("testCloneRepositoryWithBranch");
|
File directory = createTempDirectory("testCloneRepositoryWithBranch");
|
||||||
CloneCommand command = Git.cloneRepository();
|
CloneCommand command = Git.cloneRepository();
|
||||||
command.setBranch("refs/heads/master");
|
command.setBranch("refs/heads/master");
|
||||||
command.setBranchesToClone(Collections
|
command.setBranchesToClone(Collections
|
||||||
.singletonList("refs/heads/master"));
|
.singletonList("refs/heads/master"));
|
||||||
command.setDirectory(directory);
|
command.setDirectory(directory);
|
||||||
command.setURI("file://"
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
|
||||||
+ git.getRepository().getWorkTree().getPath());
|
|
||||||
Git git2 = command.call();
|
Git git2 = command.call();
|
||||||
addRepoToClose(git2.getRepository());
|
addRepoToClose(git2.getRepository());
|
||||||
assertNotNull(git2);
|
assertNotNull(git2);
|
||||||
assertEquals(git2.getRepository().getFullBranch(),
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
|
||||||
"refs/heads/master");
|
assertEquals("refs/remotes/origin/master", allRefNames(git2
|
||||||
assertEquals("refs/remotes/origin/master",
|
.branchList().setListMode(ListMode.REMOTE).call()));
|
||||||
allRefNames(git2.branchList()
|
|
||||||
.setListMode(ListMode.REMOTE).call()));
|
|
||||||
|
|
||||||
// Same thing, but now test with bare repo
|
// Same thing, but now test with bare repo
|
||||||
directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
|
directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
|
||||||
|
@ -213,19 +189,14 @@ public void testCloneRepositoryOnlyOneBranch() {
|
||||||
command.setBranchesToClone(Collections
|
command.setBranchesToClone(Collections
|
||||||
.singletonList("refs/heads/master"));
|
.singletonList("refs/heads/master"));
|
||||||
command.setDirectory(directory);
|
command.setDirectory(directory);
|
||||||
command.setURI("file://"
|
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
|
||||||
+ git.getRepository().getWorkTree().getPath());
|
|
||||||
command.setBare(true);
|
command.setBare(true);
|
||||||
git2 = command.call();
|
git2 = command.call();
|
||||||
addRepoToClose(git2.getRepository());
|
addRepoToClose(git2.getRepository());
|
||||||
assertNotNull(git2);
|
assertNotNull(git2);
|
||||||
assertEquals(git2.getRepository().getFullBranch(),
|
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
|
||||||
"refs/heads/master");
|
assertEquals("refs/heads/master", allRefNames(git2.branchList()
|
||||||
assertEquals("refs/heads/master", allRefNames(git2
|
.setListMode(ListMode.ALL).call()));
|
||||||
.branchList().setListMode(ListMode.ALL).call()));
|
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String allRefNames(List<Ref> refs) {
|
public static String allRefNames(List<Ref> refs) {
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -64,22 +63,17 @@ public void setUp() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitRepository() {
|
public void testInitRepository() throws IOException {
|
||||||
try {
|
|
||||||
File directory = createTempDirectory("testInitRepository");
|
File directory = createTempDirectory("testInitRepository");
|
||||||
InitCommand command = new InitCommand();
|
InitCommand command = new InitCommand();
|
||||||
command.setDirectory(directory);
|
command.setDirectory(directory);
|
||||||
Repository repository = command.call().getRepository();
|
Repository repository = command.call().getRepository();
|
||||||
addRepoToClose(repository);
|
addRepoToClose(repository);
|
||||||
assertNotNull(repository);
|
assertNotNull(repository);
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitBareRepository() {
|
public void testInitBareRepository() throws IOException {
|
||||||
try {
|
|
||||||
File directory = createTempDirectory("testInitBareRepository");
|
File directory = createTempDirectory("testInitBareRepository");
|
||||||
InitCommand command = new InitCommand();
|
InitCommand command = new InitCommand();
|
||||||
command.setDirectory(directory);
|
command.setDirectory(directory);
|
||||||
|
@ -88,9 +82,6 @@ public void testInitBareRepository() {
|
||||||
addRepoToClose(repository);
|
addRepoToClose(repository);
|
||||||
assertNotNull(repository);
|
assertNotNull(repository);
|
||||||
assertTrue(repository.isBare());
|
assertTrue(repository.isBare());
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File createTempDirectory(String name) throws IOException {
|
public static File createTempDirectory(String name) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue