Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.moreunit.core.matching;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.junit.Test;

public class MatchStrategyTest {

@Test
public void testAllMatchesStrategy() throws CoreException {
SourceFolderPath mockFolder = mock(SourceFolderPath.class);
when(mockFolder.isResolved()).thenReturn(true);
FileMatchCollector collector = MatchStrategy.ALL_MATCHES.createMatchCollector(mockFolder);

// acceptFile returns false to continue searching
boolean stopSearch1 = collector.acceptFile(mock(IFile.class));
boolean stopSearch2 = collector.acceptFile(mock(IFile.class));

assertFalse(stopSearch1);
assertFalse(stopSearch2);
assertEquals(2, collector.getResults().size());
}

@Test
public void testAnyMatchStrategy() throws CoreException {
SourceFolderPath mockFolder = mock(SourceFolderPath.class);
when(mockFolder.isResolved()).thenReturn(true);
FileMatchCollector collector = MatchStrategy.ANY_MATCH.createMatchCollector(mockFolder);

// First match found, continue searching from the perspective of this call returning false,
// but internal state marks it as found.
boolean stopSearch1 = collector.acceptFile(mock(IFile.class));
assertFalse(stopSearch1);
assertEquals(1, collector.getResults().size());

// Second match should be ignored, and return true to stop searching
boolean stopSearch2 = collector.acceptFile(mock(IFile.class));
assertTrue(stopSearch2);
// Size remains 1
assertEquals(1, collector.getResults().size());
}
}
Loading