-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
pitest-entry/src/main/java/org/pitest/mutationtest/verify/SpringVerifierFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.pitest.mutationtest.verify; | ||
|
||
import org.pitest.classinfo.ClassName; | ||
import org.pitest.classpath.CodeSource; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
public class SpringVerifierFactory implements BuildVerifierFactory { | ||
@Override | ||
public BuildVerifier create(CodeSource code) { | ||
return new SpringVerifier(code); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Detect missing spring plugin"; | ||
} | ||
} | ||
|
||
class SpringVerifier implements BuildVerifier { | ||
|
||
private final CodeSource code; | ||
|
||
SpringVerifier(CodeSource code) { | ||
this.code = code; | ||
} | ||
|
||
@Override | ||
public List<String> verify() { | ||
if (springIsOnClassPath() && !springPluginIsPresent()) { | ||
return asList("Project uses Spring, but the Arcmutate Spring plugin is not present (https://docs.arcmutate.com/docs/spring.html)"); | ||
} | ||
|
||
return Collections.emptyList(); | ||
} | ||
|
||
|
||
private boolean springPluginIsPresent() { | ||
return code.fetchClassBytes(ClassName.fromString("com.groupcdg.arcmutate.spring.PluginMarker")).isPresent(); | ||
} | ||
|
||
private boolean springIsOnClassPath() { | ||
return code.fetchClassBytes(ClassName.fromString("org.springframework.core.SpringVersion")).isPresent(); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
.../src/main/resources/META-INF/services/org.pitest.mutationtest.verify.BuildVerifierFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
org.pitest.mutationtest.verify.DefaultBuildVerifierFactory | ||
org.pitest.mutationtest.verify.MissingJUnit5PluginVerifierFactory | ||
org.pitest.mutationtest.verify.MissingTestNGPluginVerifierFactory | ||
org.pitest.mutationtest.verify.KotlinVerifierFactory | ||
org.pitest.mutationtest.verify.KotlinVerifierFactory | ||
org.pitest.mutationtest.verify.SpringVerifierFactory |
59 changes: 59 additions & 0 deletions
59
pitest-entry/src/test/java/org/pitest/mutationtest/verify/SpringVerifierFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.pitest.mutationtest.verify; | ||
|
||
import org.junit.Test; | ||
import org.pitest.bytecode.analysis.ClassTree; | ||
import org.pitest.classinfo.ClassName; | ||
import org.pitest.verifier.interceptors.BuildVerifierVerifier; | ||
|
||
import static org.pitest.verifier.interceptors.BuildVerifierVerifier.aValidClass; | ||
import static org.pitest.verifier.interceptors.BuildVerifierVerifier.codeSourceForClasses; | ||
import static org.pitest.verifier.interceptors.BuildVerifierVerifier.codeSourceReturning; | ||
|
||
public class SpringVerifierFactoryTest { | ||
BuildVerifierVerifier v = BuildVerifierVerifier.confirmFactory(new SpringVerifierFactory()); | ||
|
||
@Test | ||
public void isOnChain() { | ||
v.isOnChain(); | ||
} | ||
|
||
@Test | ||
public void doesNotDisplayMessageWhenSpringNotPresent() { | ||
v.withCodeSource(codeSourceReturning(ClassName.fromString("not.relevant.Foo"))) | ||
.issues() | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
public void displaysWarningWhenSpringPresentWithoutPlugin() { | ||
ClassTree springMarker = aValidClass(); | ||
springMarker.rawNode().name = "org.springframework.core.SpringVersion"; | ||
|
||
|
||
ClassTree clientCode = aValidClass(); | ||
clientCode.rawNode().name = "com.example.Foo"; | ||
clientCode.rawNode().sourceFile = "Foo.kt"; | ||
|
||
v.withCodeSource(codeSourceForClasses(springMarker, clientCode)) | ||
.issues() | ||
.isNotEmpty(); | ||
} | ||
|
||
@Test | ||
public void doesNotDisplayWarningWhenPluginPresent() { | ||
ClassTree springMarker = aValidClass(); | ||
springMarker.rawNode().name = "org.springframework.core.SpringVersion"; | ||
|
||
ClassTree pluginMarker = aValidClass(); | ||
pluginMarker.rawNode().name = "com.groupcdg.arcmutate.spring.PluginMarker"; | ||
|
||
ClassTree clientCode = aValidClass(); | ||
clientCode.rawNode().name = "com.example.Foo"; | ||
clientCode.rawNode().sourceFile = "Foo.kt"; | ||
|
||
v.withCodeSource(codeSourceForClasses(springMarker, pluginMarker, clientCode)) | ||
.issues() | ||
.isEmpty(); | ||
} | ||
} | ||
|