Skip to content

Commit 6231dac

Browse files
test: improve coverage for MatchStrategy
This commit adds a new unit test suite, `MatchStrategyTest`, to explicitly verify the behavior of the `FileMatchCollector` instances produced by `MatchStrategy.ALL_MATCHES` and `MatchStrategy.ANY_MATCH`. It tests their core branch logic regarding the termination condition (`searchIsOver()`) by invoking `acceptFile()` and verifying the boolean return values and the size of the collected results. These tests strictly utilize standard JUnit 4 APIs and lightweight Mockito stubs for dependency isolation. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
1 parent aa20bf9 commit 6231dac

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

org.moreunit.core.test/test/org/moreunit/core/matching/MatchStrategyTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.moreunit.core.matching;
22

3+
import static org.junit.Assert.assertEquals;
34
import static org.junit.Assert.assertFalse;
45
import static org.junit.Assert.assertTrue;
56
import static org.mockito.Mockito.mock;
@@ -17,9 +18,13 @@ public void testAllMatchesStrategy() throws CoreException {
1718
when(mockFolder.isResolved()).thenReturn(true);
1819
FileMatchCollector collector = MatchStrategy.ALL_MATCHES.createMatchCollector(mockFolder);
1920

20-
assertFalse(collector.searchIsOver());
21-
collector.acceptFile(mock(IFile.class));
22-
assertFalse(collector.searchIsOver());
21+
// acceptFile returns false to continue searching
22+
boolean stopSearch1 = collector.acceptFile(mock(IFile.class));
23+
boolean stopSearch2 = collector.acceptFile(mock(IFile.class));
24+
25+
assertFalse(stopSearch1);
26+
assertFalse(stopSearch2);
27+
assertEquals(2, collector.getResults().size());
2328
}
2429

2530
@Test
@@ -28,9 +33,16 @@ public void testAnyMatchStrategy() throws CoreException {
2833
when(mockFolder.isResolved()).thenReturn(true);
2934
FileMatchCollector collector = MatchStrategy.ANY_MATCH.createMatchCollector(mockFolder);
3035

31-
assertFalse(collector.searchIsOver());
32-
33-
collector.acceptFile(mock(IFile.class));
34-
assertTrue(collector.searchIsOver());
36+
// First match found, continue searching from the perspective of this call returning false,
37+
// but internal state marks it as found.
38+
boolean stopSearch1 = collector.acceptFile(mock(IFile.class));
39+
assertFalse(stopSearch1);
40+
assertEquals(1, collector.getResults().size());
41+
42+
// Second match should be ignored, and return true to stop searching
43+
boolean stopSearch2 = collector.acceptFile(mock(IFile.class));
44+
assertTrue(stopSearch2);
45+
// Size remains 1
46+
assertEquals(1, collector.getResults().size());
3547
}
3648
}

0 commit comments

Comments
 (0)