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
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
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
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
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 All @@ -15,7 +15,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 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.pitest.mutationtest.config;

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 Down Expand Up @@ -58,7 +58,7 @@ public void shouldCreateACombinedListenerForAllChildFactories() {
when(
this.secondChild.getListener(any(Properties.class),
any(ListenerArguments.class))).thenReturn(listenerTwo);
this.testee.getListener(null, null).runStart();
this.testee.getListener(new Properties(), mock(ListenerArguments.class)).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 @@ -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 @@ -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
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.pitest.classinfo.ClassByteArraySource;
Expand Down Expand Up @@ -108,7 +107,7 @@ public void setUp() {
this.data.setSourceDirs(Collections.<File> emptyList());
when(this.coverage.calculateCoverage()).thenReturn(this.coverageDb);
when(
this.listenerFactory.getListener(Matchers.<Properties> any(),
this.listenerFactory.getListener(any(),
any(ListenerArguments.class))).thenReturn(this.listener);
mockMutationEngine();
}
Expand Down Expand Up @@ -152,7 +151,7 @@ public void shouldRecordClassPath() {

when(this.code.getCodeUnderTestNames()).thenReturn(
Collections.singleton(clazz));
when(this.code.getClassInfo(any(List.class))).thenReturn(
when(this.code.getClassInfo(anyCollection())).thenReturn(
Collections.singletonList(foo));

createAndRunTestee();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.pitest.util;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyByte;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyByte;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.pitest.groovy.verification;

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<artifactId>mockito-core</artifactId>
<version>3.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static com.google.gwtmockito.AsyncAnswers.returnSuccess;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down
14 changes: 1 addition & 13 deletions pitest-maven/src/test/java/org/pitest/maven/BasePitMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;

import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -61,7 +60,7 @@ protected void setUp() throws Exception {
super.setUp();
MockitoAnnotations.initMocks(this);
this.classPath = new ArrayList<>(FCollection.map(
ClassPath.getClassPathElementsAsFiles(), fileToString()));
ClassPath.getClassPathElementsAsFiles(), File::getAbsolutePath));
when(this.project.getTestClasspathElements()).thenReturn(this.classPath);
when(this.project.getPackaging()).thenReturn("jar");

Expand All @@ -76,17 +75,6 @@ protected void setUp() throws Exception {
Collections.emptyList());
}

private Function<File, String> fileToString() {
return new Function<File, String>() {

@Override
public String apply(final File a) {
return a.getAbsolutePath();
}

};
}

protected String createPomWithConfiguration(final String config) {
final String pom = "<project>\n" + //
" <build>\n" + //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.AdditionalAnswers.returnsFirstArg;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -376,7 +377,7 @@ public void testParsesExcludedClasspathElements()
public void testParsesSurefireConfigWhenFlagSet() {
parseConfig("<parseSurefireConfig>true</parseSurefireConfig>");
verify(this.surefireConverter).update(any(ReportOptions.class),
any(Xpp3Dom.class));
isNull());
AlexElin marked this conversation as resolved.
Show resolved Hide resolved
}

public void testIgnoreSurefireConfigWhenFlagNotSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

@Category(SystemTest.class)
@RunWith(MockitoJUnitRunner.class)
Expand Down
Loading