Browse Source

PostOrderTreeWalkTest: Open TreeWalk in try-with-resource

Also remove unnecessary nesting in test methods.

Change-Id: Id59f8403c0a7b38ebb6b3a24814257cd59ea575d
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.2
David Pursehouse 9 years ago
parent
commit
a3923f6b95
  1. 24
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java

24
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java

@ -60,23 +60,25 @@ import org.junit.Test;
public class PostOrderTreeWalkTest extends RepositoryTestCase {
@Test
public void testInitialize_NoPostOrder() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
assertFalse(tw.isPostOrderTraversal());
}
}
@Test
public void testInitialize_TogglePostOrder() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
assertFalse(tw.isPostOrderTraversal());
tw.setPostOrderTraversal(true);
assertTrue(tw.isPostOrderTraversal());
tw.setPostOrderTraversal(false);
assertFalse(tw.isPostOrderTraversal());
}
}
@Test
public void testResetDoesNotAffectPostOrder() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
assertTrue(tw.isPostOrderTraversal());
tw.reset();
@ -87,11 +89,11 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
tw.reset();
assertFalse(tw.isPostOrderTraversal());
}
}
@Test
public void testNoPostOrder() throws Exception {
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
b.add(makeFile("a"));
@ -101,9 +103,8 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
}
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(false);
tw.addTree(new DirCacheIterator(tree));
@ -116,11 +117,11 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
assertModes("b/d", REGULAR_FILE, tw);
assertModes("q", REGULAR_FILE, tw);
}
}
@Test
public void testWithPostOrder_EnterSubtree() throws Exception {
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
b.add(makeFile("a"));
@ -130,9 +131,8 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
}
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
tw.addTree(new DirCacheIterator(tree));
@ -151,11 +151,11 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
assertModes("q", REGULAR_FILE, tw);
}
}
@Test
public void testWithPostOrder_NoEnterSubtree() throws Exception {
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
b.add(makeFile("a"));
@ -165,9 +165,8 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
}
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
tw.addTree(new DirCacheIterator(tree));
@ -179,6 +178,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
assertModes("q", REGULAR_FILE, tw);
}
}
private DirCacheEntry makeFile(final String path) throws Exception {
return createEntry(path, REGULAR_FILE);

Loading…
Cancel
Save