Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Frade2018-10-30 19:31:48 +0000
committerIvan Frade2018-10-30 20:08:16 +0000
commit17dbaa4fdd06524da18c37299842832c5d00e24b (patch)
tree18c4516ecf5b449a05062621e0fc230dc1ca57a3
parentd0f44d43968e83699e87d6dcc73eb86de203e0a9 (diff)
downloadjgit-17dbaa4fdd06524da18c37299842832c5d00e24b.tar.gz
jgit-17dbaa4fdd06524da18c37299842832c5d00e24b.tar.xz
jgit-17dbaa4fdd06524da18c37299842832c5d00e24b.zip
RepoCommandTest: Extract method to assert file contents
Many tests verify the contents of files in a try-with-resources incantation that clutters the code. Extract that verification to an "assertContents" method, that is easier to read. Change-Id: If430eac6f5b9ae352e42b2d43867ceb6cd618fbb Signed-off-by: Ivan Frade <ifrade@google.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java59
1 files changed, 17 insertions, 42 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
index 3b330ab3b8..022f6433d2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
@@ -55,6 +55,7 @@ import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
@@ -199,6 +200,15 @@ public class RepoCommandTest extends RepositoryTestCase {
return r;
}
+ private static void assertContents(Path path, String expected)
+ throws IOException {
+ try (BufferedReader reader = Files.newBufferedReader(path, UTF_8)) {
+ String content = reader.readLine();
+ assertEquals("Unexpected content in " + path.getFileName(),
+ expected, content);
+ }
+ }
+
@Test
public void runTwiceIsNOP() throws Exception {
try (Repository child = cloneRepository(groupADb, true);
@@ -474,12 +484,7 @@ public class RepoCommandTest extends RepositoryTestCase {
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
assertTrue("submodule should be checked out", hello.exists());
- try (BufferedReader reader = Files.newBufferedReader(hello.toPath(),
- UTF_8)) {
- String content = reader.readLine();
- assertEquals("submodule content should be as expected",
- "master world", content);
- }
+ assertContents(hello.toPath(), "master world");
}
@Test
@@ -565,21 +570,11 @@ public class RepoCommandTest extends RepositoryTestCase {
// The original file should exist
File hello = new File(localDb.getWorkTree(), "foo/hello.txt");
assertTrue("The original file should exist", hello.exists());
- try (BufferedReader reader = Files.newBufferedReader(hello.toPath(),
- UTF_8)) {
- String content = reader.readLine();
- assertEquals("The original file should have expected content",
- "master world", content);
- }
+ assertContents(hello.toPath(), "master world");
// The dest file should also exist
hello = new File(localDb.getWorkTree(), "Hello");
assertTrue("The destination file should exist", hello.exists());
- try (BufferedReader reader = Files.newBufferedReader(hello.toPath(),
- UTF_8)) {
- String content = reader.readLine();
- assertEquals("The destination file should have expected content",
- "master world", content);
- }
+ assertContents(hello.toPath(), "master world");
}
@Test
@@ -671,12 +666,7 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- try (BufferedReader reader = Files.newBufferedReader(hello.toPath(),
- UTF_8)) {
- String content = reader.readLine();
- assertEquals("submodule content should be as expected",
- "branch world", content);
- }
+ assertContents(hello.toPath(), "branch world");
}
@Test
@@ -698,12 +688,7 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- try (BufferedReader reader = Files.newBufferedReader(hello.toPath(),
- UTF_8)) {
- String content = reader.readLine();
- assertEquals("submodule content should be as expected",
- "branch world", content);
- }
+ assertContents(hello.toPath(), "branch world");
}
@Test
@@ -771,12 +756,7 @@ public class RepoCommandTest extends RepositoryTestCase {
assertFalse("The foo/Hello file should be skipped",
foohello.exists());
// The content of Hello file should be expected
- try (BufferedReader reader = Files.newBufferedReader(hello.toPath(),
- UTF_8)) {
- String content = reader.readLine();
- assertEquals("The Hello file should have expected content",
- "branch world", content);
- }
+ assertContents(hello.toPath(), "branch world");
}
}
@@ -1143,12 +1123,7 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- try (BufferedReader reader = Files.newBufferedReader(hello.toPath(),
- UTF_8)) {
- String content = reader.readLine();
- assertEquals("submodule content should be as expected",
- "branch world", content);
- }
+ assertContents(hello.toPath(), "branch world");
}
@Test

Back to the top