Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to mockito 3 #753

Merged
merged 10 commits into from
Feb 17, 2021
11 changes: 5 additions & 6 deletions pitest-ant/src/test/java/org/pitest/ant/PitestTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package org.pitest.ant;

import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.startsWith;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
Expand All @@ -36,7 +36,7 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.pitest.mutationtest.commandline.MutationCoverageReport;

@RunWith(MockitoJUnitRunner.class)
Expand Down Expand Up @@ -489,7 +489,7 @@ public void shouldPassMutationMatrixFlagToJavaTask() {
verify(this.arg).setValue("--fullMutationMatrix=true");
}

private static class PathMatcher extends ArgumentMatcher<Path> {
private static class PathMatcher implements ArgumentMatcher<Path> {

private final String[] expectedPaths;

Expand All @@ -498,8 +498,7 @@ public PathMatcher(final String path) {
}

@Override
public boolean matches(final Object argument) {
final Path argPath = (Path) argument;
public boolean matches(final Path argPath) {
final String[] paths = argPath.toString().split(File.pathSeparator);
final boolean matches = paths.length == this.expectedPaths.length;
if (matches) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.config.ReportOptions.DEFAULT_CHILD_JVM_ARGS;

Expand Down Expand Up @@ -56,7 +56,7 @@ public class OptionsParserTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
when(this.filter.test(any(String.class))).thenReturn(true);
this.testee = new OptionsParser(this.filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class MockitoRunnerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -47,7 +47,7 @@ public class RepositoryTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.testee = new Repository(new ClassloaderByteArraySource(
IsolationUtils.getContextClassLoader()), this.hashFunction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TestToClassMapperTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.repository = new Repository(this.source);
this.testee = new TestToClassMapper(this.repository);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.pitest.coverage.CoverageMother.aBlockLocation;
Expand Down Expand Up @@ -65,7 +65,7 @@ public class CoverageDataTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
when(this.lm.mapLines(any(ClassName.class))).thenReturn(
new HashMap<BlockLocation, Set<Integer>>());
when(this.code.findTestee(any())).thenReturn(Optional.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ReceiveTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.handler = stubHandler();
this.testee = new Receive(this.handler);
this.description = new Description("foo", "bar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SendDataTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.testClasses = new ArrayList<>();
this.testee = new SendData(this.arguments, this.testClasses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class TestMutationTesting {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.config = TestPluginArguments.defaults().withTestPlugin(SimpleTestPlugin.NAME);
this.metaDataExtractor = new MetaDataExtractor();
this.mae = new MutationAnalysisExecutor(1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.pitest.mutationtest.build;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.engine.MutationDetailsMother.aMutationDetail;
Expand All @@ -13,7 +13,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.mutationtest.engine.Mutater;
import org.pitest.mutationtest.engine.MutationDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.pitest.mutationtest.build;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.LocationMother.aLocation;

Expand Down Expand Up @@ -39,7 +39,7 @@ public class DefaultTestPrioritiserTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.testee = new DefaultTestPrioritiser(this.coverage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class KnownStatusMutationTestUnitTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.pitest.classinfo.ClassByteArraySource;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.ClassloaderByteArraySource;
Expand All @@ -25,7 +25,7 @@
import java.util.function.Function;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.LocationMother.aLocation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.LocationMother.aLocation;
import static org.pitest.mutationtest.LocationMother.aMutationId;
Expand Down Expand Up @@ -31,7 +31,7 @@ public class MutationTestBuilderTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
makeTesteeWithUnitSizeOf(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class MutationTestUnitTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.mutationConfig = new MutationConfig(this.engine, new LaunchOptions(
this.javaAgent));
this.mutations = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -44,7 +44,7 @@ public class CompoundListenerFactoryTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);

when(firstChild.provides()).thenReturn(MutationResultListenerFactory.LEGACY_MODE);
when(secondChild.provides()).thenReturn(MutationResultListenerFactory.LEGACY_MODE);
Expand All @@ -63,7 +63,7 @@ public void shouldCreateACombinedListenerForAllChildFactories() {
when(
this.secondChild.getListener(any(Properties.class),
any(ListenerArguments.class))).thenReturn(listenerTwo);
this.testee.getListener(null, someArgs()).runStart();
this.testee.getListener(new Properties(), someArgs()).runStart();
verify(listenerOne, times(1)).runStart();
verify(listenerTwo, times(1)).runStart();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CompoundTestListenerTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.testee = new CompoundTestListener(Arrays.asList(this.firstChild,
this.secondChild));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DefaultCodeHistoryTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.testee = new DefaultCodeHistory(this.classInfoSource, this.results,
this.historicClassPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class HistoryListenerTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.testee = new HistoryListener(this.store);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.DetectionStatus.KILLED;
import static org.pitest.mutationtest.DetectionStatus.NOT_STARTED;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void configureLogCatcher() {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.testee = new IncrementalAnalyser(this.history, this.coverage);
}

Expand Down Expand Up @@ -98,6 +98,8 @@ public void shouldStartNewMutationsAtAStatusOfNotStarted() {
public void shouldStartPreviousSurvivedMutationsAtAStatusOfNotStartedWhenCoverageHasChanged() {
final MutationDetails md = makeMutation("foo");
setHistoryForAllMutationsTo(DetectionStatus.SURVIVED);
when(coverage.getCoverageIdForClass(any(ClassName.class)))
.thenReturn(BigInteger.ONE);
when(
this.history.hasCoverageChanged(any(ClassName.class),
any(BigInteger.class))).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import java.io.IOException;
Expand Down Expand Up @@ -62,7 +62,7 @@ public void close() {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
when(this.coverage.getCoverageIdForClass(any(ClassName.class))).thenReturn(
BigInteger.TEN);
}
Expand Down Expand Up @@ -148,4 +148,4 @@ private void recordClassPathWithTestee(
this.testee.recordClassPath(ids, this.coverage);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CSVReportListenerTest {

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.testee = new CSVReportListener(this.out);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.pitest.mutationtest.tooling;

import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -39,7 +39,7 @@ public class DirectorySourceLocatorTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
this.root = new File(".");
this.testee = new DirectorySourceLocator(this.root, this.locator);
when(this.locator.apply(any(File.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

public class JarCreatingJarFinderTest {
Expand All @@ -51,7 +51,7 @@ public class JarCreatingJarFinderTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
when(this.byteSource.getBytes(anyString())).thenReturn(
Optional.ofNullable(new byte[1]));
this.testee = new JarCreatingJarFinder(this.byteSource);
Expand Down
Loading