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

warn when spring plugin not present #1206

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}