Skip to content

Commit

Permalink
Added default warn strictness if no strictness modifiers are used. (#626
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Jenson3210 authored Oct 30, 2024
1 parent 6820b1b commit d856596
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
maybeAddImport("org.junit.jupiter.api.extension.ExtendWith");
maybeAddImport("org.mockito.junit.jupiter.MockitoExtension");

if (strictness != null) {
if (strictness == null) {
// As we are in a Rule, and rules where always warn by default,
// we cannot use junit5 Strictness.STRICT_STUBS during migration
strictness = "Strictness.WARN";
}
if (!strictness.contains("STRICT_STUBS")) {
cd = JavaTemplate.builder("@MockitoSettings(strictness = " + strictness + ")")
.doBeforeParseTemplate(System.out::println)
.javaParser(JavaParser.fromJavaVersion()
Expand Down Expand Up @@ -156,7 +161,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
strictness = "Strictness.LENIENT";
break;
}
if (strictness != null && !strictness.contains("STRICT_STUBS")) {
if (strictness != null) {
strictness = strictness.startsWith("Strictness.") ? strictness : "Strictness." + strictness;
getCursor().putMessageOnFirstEnclosing(J.ClassDeclaration.class, STRICTNESS_KEY, strictness);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ class MyTest {
import org.junit.rules.TemporaryFolder;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
class MyTest {
@Rule
Expand Down Expand Up @@ -103,9 +106,12 @@ class MyTest {
import org.junit.runners.MethodSorters;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
@ExtendWith(MockitoExtension.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@MockitoSettings(strictness = Strictness.WARN)
class MyTest {
}
"""
Expand Down Expand Up @@ -266,12 +272,15 @@ public void exampleTest() {
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.VerificationCollector;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import java.util.List;
import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
class MyTest {
@Rule
Expand Down

0 comments on commit d856596

Please sign in to comment.