DirCacheIteratorTest: Open TreeWalk instances in try-with-resource
Change-Id: If23597acaebf2295b85411bf87bc0292d5dc789e Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
parent
430b777830
commit
30c9ec88d1
|
@ -76,10 +76,11 @@ public void testEmptyTree_WithTreeWalk() throws Exception {
|
||||||
final DirCache dc = DirCache.newInCore();
|
final DirCache dc = DirCache.newInCore();
|
||||||
assertEquals(0, dc.getEntryCount());
|
assertEquals(0, dc.getEntryCount());
|
||||||
|
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
tw.addTree(new DirCacheIterator(dc));
|
tw.addTree(new DirCacheIterator(dc));
|
||||||
assertFalse(tw.next());
|
assertFalse(tw.next());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoSubtree_NoTreeWalk() throws Exception {
|
public void testNoSubtree_NoTreeWalk() throws Exception {
|
||||||
|
@ -125,7 +126,7 @@ public void testNoSubtree_WithTreeWalk() throws Exception {
|
||||||
b.finish();
|
b.finish();
|
||||||
|
|
||||||
final DirCacheIterator i = new DirCacheIterator(dc);
|
final DirCacheIterator i = new DirCacheIterator(dc);
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
tw.addTree(i);
|
tw.addTree(i);
|
||||||
int pathIdx = 0;
|
int pathIdx = 0;
|
||||||
while (tw.next()) {
|
while (tw.next()) {
|
||||||
|
@ -139,6 +140,7 @@ public void testNoSubtree_WithTreeWalk() throws Exception {
|
||||||
}
|
}
|
||||||
assertEquals(paths.length, pathIdx);
|
assertEquals(paths.length, pathIdx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleSubtree_NoRecursion() throws Exception {
|
public void testSingleSubtree_NoRecursion() throws Exception {
|
||||||
|
@ -162,7 +164,7 @@ public void testSingleSubtree_NoRecursion() throws Exception {
|
||||||
final int expPos[] = { 0, -1, 4 };
|
final int expPos[] = { 0, -1, 4 };
|
||||||
|
|
||||||
final DirCacheIterator i = new DirCacheIterator(dc);
|
final DirCacheIterator i = new DirCacheIterator(dc);
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
tw.addTree(i);
|
tw.addTree(i);
|
||||||
tw.setRecursive(false);
|
tw.setRecursive(false);
|
||||||
int pathIdx = 0;
|
int pathIdx = 0;
|
||||||
|
@ -183,6 +185,7 @@ public void testSingleSubtree_NoRecursion() throws Exception {
|
||||||
}
|
}
|
||||||
assertEquals(expPaths.length, pathIdx);
|
assertEquals(expPaths.length, pathIdx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleSubtree_Recursive() throws Exception {
|
public void testSingleSubtree_Recursive() throws Exception {
|
||||||
|
@ -202,7 +205,7 @@ public void testSingleSubtree_Recursive() throws Exception {
|
||||||
b.finish();
|
b.finish();
|
||||||
|
|
||||||
final DirCacheIterator i = new DirCacheIterator(dc);
|
final DirCacheIterator i = new DirCacheIterator(dc);
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
tw.addTree(i);
|
tw.addTree(i);
|
||||||
tw.setRecursive(true);
|
tw.setRecursive(true);
|
||||||
int pathIdx = 0;
|
int pathIdx = 0;
|
||||||
|
@ -218,6 +221,7 @@ public void testSingleSubtree_Recursive() throws Exception {
|
||||||
}
|
}
|
||||||
assertEquals(paths.length, pathIdx);
|
assertEquals(paths.length, pathIdx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTwoLevelSubtree_Recursive() throws Exception {
|
public void testTwoLevelSubtree_Recursive() throws Exception {
|
||||||
|
@ -236,7 +240,7 @@ public void testTwoLevelSubtree_Recursive() throws Exception {
|
||||||
b.add(ents[i]);
|
b.add(ents[i]);
|
||||||
b.finish();
|
b.finish();
|
||||||
|
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
tw.addTree(new DirCacheIterator(dc));
|
tw.addTree(new DirCacheIterator(dc));
|
||||||
tw.setRecursive(true);
|
tw.setRecursive(true);
|
||||||
int pathIdx = 0;
|
int pathIdx = 0;
|
||||||
|
@ -252,6 +256,7 @@ public void testTwoLevelSubtree_Recursive() throws Exception {
|
||||||
}
|
}
|
||||||
assertEquals(paths.length, pathIdx);
|
assertEquals(paths.length, pathIdx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReset() throws Exception {
|
public void testReset() throws Exception {
|
||||||
|
@ -397,7 +402,7 @@ public void testTwoLevelSubtree_FilterPath() throws Exception {
|
||||||
b.add(ents[i]);
|
b.add(ents[i]);
|
||||||
b.finish();
|
b.finish();
|
||||||
|
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
|
for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
|
||||||
tw.reset();
|
tw.reset();
|
||||||
tw.addTree(new DirCacheIterator(dc));
|
tw.addTree(new DirCacheIterator(dc));
|
||||||
|
@ -415,6 +420,7 @@ public void testTwoLevelSubtree_FilterPath() throws Exception {
|
||||||
assertFalse(tw.next());
|
assertFalse(tw.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemovedSubtree() throws Exception {
|
public void testRemovedSubtree() throws Exception {
|
||||||
|
@ -424,7 +430,7 @@ public void testRemovedSubtree() throws Exception {
|
||||||
final DirCache dc = DirCache.read(path, FS.DETECTED);
|
final DirCache dc = DirCache.read(path, FS.DETECTED);
|
||||||
assertEquals(2, dc.getEntryCount());
|
assertEquals(2, dc.getEntryCount());
|
||||||
|
|
||||||
final TreeWalk tw = new TreeWalk(db);
|
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||||
tw.setRecursive(true);
|
tw.setRecursive(true);
|
||||||
tw.addTree(new DirCacheIterator(dc));
|
tw.addTree(new DirCacheIterator(dc));
|
||||||
|
|
||||||
|
@ -438,4 +444,5 @@ public void testRemovedSubtree() throws Exception {
|
||||||
|
|
||||||
assertFalse(tw.next());
|
assertFalse(tw.next());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue