Skip to content

Commit aa20bf9

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()`). These tests strictly utilize standard JUnit 4 APIs and Mockito for dependency isolation, and maintain full compatibility with the existing test infrastructure. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
1 parent 28a1baa commit aa20bf9

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.moreunit.core.matching;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
import static org.mockito.Mockito.mock;
6+
import static org.mockito.Mockito.when;
7+
8+
import org.eclipse.core.resources.IFile;
9+
import org.eclipse.core.runtime.CoreException;
10+
import org.junit.Test;
11+
12+
public class MatchStrategyTest {
13+
14+
@Test
15+
public void testAllMatchesStrategy() throws CoreException {
16+
SourceFolderPath mockFolder = mock(SourceFolderPath.class);
17+
when(mockFolder.isResolved()).thenReturn(true);
18+
FileMatchCollector collector = MatchStrategy.ALL_MATCHES.createMatchCollector(mockFolder);
19+
20+
assertFalse(collector.searchIsOver());
21+
collector.acceptFile(mock(IFile.class));
22+
assertFalse(collector.searchIsOver());
23+
}
24+
25+
@Test
26+
public void testAnyMatchStrategy() throws CoreException {
27+
SourceFolderPath mockFolder = mock(SourceFolderPath.class);
28+
when(mockFolder.isResolved()).thenReturn(true);
29+
FileMatchCollector collector = MatchStrategy.ANY_MATCH.createMatchCollector(mockFolder);
30+
31+
assertFalse(collector.searchIsOver());
32+
33+
collector.acceptFile(mock(IFile.class));
34+
assertTrue(collector.searchIsOver());
35+
}
36+
}

0 commit comments

Comments
 (0)