Skip to content

Commit

Permalink
Merge pull request #1206 from hcoles/feature/spring_warning
Browse files Browse the repository at this point in the history
warn when spring plugin not present
  • Loading branch information
hcoles authored May 11, 2023
2 parents 19327c4 + c56ec6f commit 0c4a45b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class KotlinVerifier implements BuildVerifier {
@Override
public List<String> verify() {
if (kotlinIsOnClassPath() && !kotlinPluginIsPresent() && kotlinClassesToBeMutated()) {
return asList("Project uses kotlin, but the Arcmutate kotlin plugin is not on classpath (https://docs.arcmutate.com/docs/kotlin.html)");
return asList("Project uses kotlin, but the Arcmutate kotlin plugin is not present (https://docs.arcmutate.com/docs/kotlin.html)");
}

return Collections.emptyList();
Expand Down
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();
}
}
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
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();
}
}

0 comments on commit 0c4a45b

Please sign in to comment.