Skip to content

Commit

Permalink
Refactor: methodadd methodgen amplifiers FIX #844 (#846)
Browse files Browse the repository at this point in the history
* refactor: rename MethodAdd to MethodDuplicationAmplifier and MethodGenerator to MethodAdderOnExistingObjectsAmplifier

* doc: update documentation with new values
  • Loading branch information
danglotb authored Jul 24, 2019
1 parent 7f20fa7 commit 7469c84
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 50 deletions.
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,25 @@ Usage: java -jar target/dspot-<version>-jar-with-dependencies.jar
properties) of the target project (e.g. ./foo.properties).
[(-a|--amplifiers) Amplifier1:Amplifier2:...:AmplifierN ]
[optional] specify the list of amplifiers to use. By default, DSpot does
not use any amplifiers (None) and applies only assertion amplification.
Possible values are:
- MethodAdd
- MethodRemove
- FastLiteralAmplifier
- MethodGeneratorAmplifier
- ReturnValueAmplifier
- StringLiteralAmplifier
- NumberLiteralAmplifier
- BooleanLiteralAmplifier
- CharLiteralAmplifier
- AllLiteralAmplifiers
- NullifierAmplifier
- None
(default: None)
[optional] specify the list of amplifiers to use. By default, DSpot does
not use any amplifiers (None) and applies only assertion amplification.
Possible values are:
- MethodAdd
- MethodDuplicationAmplifier
- MethodRemove
- FastLiteralAmplifier
- TestDataMutator
- MethodGeneratorAmplifier
- MethodAdderOnExistingObjectsAmplifier
- ReturnValueAmplifier
- StringLiteralAmplifier
- NumberLiteralAmplifier
- BooleanLiteralAmplifier
- CharLiteralAmplifier
- AllLiteralAmplifiers
- NullifierAmplifier
- None
(default: None)
[(-i|--iteration) <iteration>]
[optional] specify the number of amplification iterations. A larger
Expand Down
4 changes: 3 additions & 1 deletion dspot-maven/src/main/java/eu/stamp_project/DSpotMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public class DSpotMojo extends AbstractMojo {
* [optional] specify the list of amplifiers to use. By default, DSpot does not use any amplifiers (None) and applies only assertion amplification.
* Possible values are:
* - MethodAdd
* - MethodDuplicationAmplifier
* - MethodRemove
* - FastLiteralAmplifier
* - MethodGeneratorAmplifier
* - TestDataMutator
* - MethodAdderOnExistingObjectsAmplifier
* - ReturnValueAmplifier
* - StringLiteralAmplifier
* - NumberLiteralAmplifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* on 19/07/18
*/
@SuppressWarnings("unchecked")
public class MethodGeneratorAmplifier implements Amplifier {
public class MethodAdderOnExistingObjectsAmplifier implements Amplifier {

@Override
public Stream<CtMethod<?>> amplify(CtMethod<?> testMethod, int iteration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.stream.Stream;


public class TestMethodCallAdder implements Amplifier {
public class MethodDuplicationAmplifier implements Amplifier {

public Stream<CtMethod<?>> amplify(CtMethod<?> method, int iteration) {
if (method.getDeclaringType() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import eu.stamp_project.dspot.amplifier.*;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;

public enum AmplifierEnum {

MethodAdd(new TestMethodCallAdder()),
MethodAdd(new MethodDuplicationAmplifier()),
MethodDuplicationAmplifier(new MethodDuplicationAmplifier()),
MethodRemove(new TestMethodCallRemover()),
FastLiteralAmplifier(new FastLiteralAmplifier()),
TestDataMutator(new FastLiteralAmplifier()),
MethodGeneratorAmplifier(new MethodGeneratorAmplifier()),
MethodGeneratorAmplifier(new MethodAdderOnExistingObjectsAmplifier()),
MethodAdderOnExistingObjectsAmplifier(new MethodAdderOnExistingObjectsAmplifier()),
ReturnValueAmplifier(new ReturnValueAmplifier()),
StringLiteralAmplifier(new StringLiteralAmplifier()),
NumberLiteralAmplifier(new NumberLiteralAmplifier()),
Expand All @@ -26,14 +26,22 @@ public enum AmplifierEnum {

public final Amplifier amplifier;

private static final Map<String,String> deprecatedValuesToNewNames = new HashMap<>();

static {
deprecatedValuesToNewNames.put("MethodAdd", "MethodDuplicationAmplifier");
deprecatedValuesToNewNames.put("TestDataMutator", "FastLiteralAmplifier");
deprecatedValuesToNewNames.put("MethodGeneratorAmplifier", "MethodAdderOnExistingObjectsAmplifier");
}

private AmplifierEnum(Amplifier amplifier) {
this.amplifier = amplifier;
}

private static Amplifier stringToAmplifier(String amplifier) {
try {
if ("TestDataMutator".equals(amplifier)) {
JSAPOptions.LOGGER.warn("You are using an old name for TestDataMutator.");
if (deprecatedValuesToNewNames.containsKey(amplifier)) {
JSAPOptions.LOGGER.warn("You are using an old name: " + amplifier + ".");
JSAPOptions.LOGGER.warn("You should use the new name: FastLiteralAmplifier.");
JSAPOptions.LOGGER.warn("The entry TestDataMutator will be deleted very soon.");
}
Expand Down
6 changes: 3 additions & 3 deletions dspot/src/test/java/eu/stamp_project/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void testOverrideExistingResults() throws Exception {
Main.main(new String[]{
"--path-to-properties", "src/test/resources/test-projects/test-projects.properties",
"--test-criterion", "JacocoCoverageSelector",
"--amplifiers", "MethodAdd" + AmplificationHelper.PATH_SEPARATOR + "FastLiteralAmplifier" + AmplificationHelper.PATH_SEPARATOR + "MethodGeneratorAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier",
"--amplifiers", "MethodAdd" + AmplificationHelper.PATH_SEPARATOR + "FastLiteralAmplifier" + AmplificationHelper.PATH_SEPARATOR + "MethodAdderOnExistingObjectsAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier",
"--iteration", "1",
"--random-seed", "72",
"--test", "example.TestSuiteExample",
Expand Down Expand Up @@ -343,7 +343,7 @@ public void testOverrideExistingResults() throws Exception {
Main.main(new String[]{
"--path-to-properties", "src/test/resources/test-projects/test-projects.properties",
"--test-criterion", "JacocoCoverageSelector",
"--amplifiers", "MethodGeneratorAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier",
"--amplifiers", "MethodAdderOnExistingObjectsAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier",
"--iteration", "1",
"--random-seed", "72",
"--test", "example.TestSuiteExample",
Expand All @@ -363,7 +363,7 @@ public void testOverrideExistingResults() throws Exception {
Main.main(new String[]{
"--path-to-properties", "src/test/resources/test-projects/test-projects.properties",
"--test-criterion", "JacocoCoverageSelector",
"--amplifiers", "MethodGeneratorAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier",
"--amplifiers", "MethodAdderOnExistingObjectsAmplifier" + AmplificationHelper.PATH_SEPARATOR + "ReturnValueAmplifier",
"--iteration", "1",
"--random-seed", "72",
"--test", "example.TestSuiteExample",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eu.stamp_project.dspot;

import eu.stamp_project.AbstractTest;
import eu.stamp_project.dspot.amplifier.MethodGeneratorAmplifier;
import eu.stamp_project.dspot.amplifier.MethodAdderOnExistingObjectsAmplifier;
import eu.stamp_project.dspot.amplifier.ReturnValueAmplifier;
import eu.stamp_project.dspot.amplifier.value.ValueCreator;
import eu.stamp_project.dspot.selector.JacocoCoverageSelector;
Expand Down Expand Up @@ -42,7 +42,7 @@ public void test() throws Exception {
ValueCreator.count = 0;
RandomHelper.setSeedRandom(23L);
final InputConfiguration configuration = InputConfiguration.get();
configuration.setAmplifiers(Arrays.asList(new MethodGeneratorAmplifier(), new ReturnValueAmplifier()));
configuration.setAmplifiers(Arrays.asList(new MethodAdderOnExistingObjectsAmplifier(), new ReturnValueAmplifier()));
DSpot dspot = new DSpot( 1, configuration.getAmplifiers(), new JacocoCoverageSelector());
try {
FileUtils.cleanDirectory(new File(configuration.getOutputDirectory()));
Expand Down
4 changes: 2 additions & 2 deletions dspot/src/test/java/eu/stamp_project/dspot/DSpotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import eu.stamp_project.AbstractTest;
import eu.stamp_project.Utils;
import eu.stamp_project.dspot.amplifier.Amplifier;
import eu.stamp_project.dspot.amplifier.TestMethodCallAdder;
import eu.stamp_project.dspot.amplifier.MethodDuplicationAmplifier;
import eu.stamp_project.dspot.selector.JacocoCoverageSelector;
import eu.stamp_project.dspot.selector.TakeAllSelector;
import eu.stamp_project.dspot.selector.TestSelector;
Expand Down Expand Up @@ -73,7 +73,7 @@ public void testExcludedClassesInPropertyFile() throws Exception {
*/

final MockDSpot dSpot = new MockDSpot(1,
Collections.singletonList(new TestMethodCallAdder()),
Collections.singletonList(new MethodDuplicationAmplifier()),
new JacocoCoverageSelector()
);
// the test class fr.inria.filter.passing.PassingTest has 3 methods, but only two are amplified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
* [email protected]
* on 19/07/18
*/
public class MethodGeneratorAmplifierTest extends AbstractTest {
public class MethodAdderOnExistingObjectsAmplifierTest extends AbstractTest {

@Test
public void testInLoop() throws Exception {

/*
Test that MethodGeneratorAmplifier amplifier is able to add statement inside a loop if this loop has not brackets
Test that MethodAdderOnExistingObjectsAmplifier amplifier is able to add statement inside a loop if this loop has not brackets
*/

final String packageName = "fr.inria.statementadd";
final Factory factory = Utils.getFactory();
RandomHelper.setSeedRandom(32L);
MethodGeneratorAmplifier amplifier = new MethodGeneratorAmplifier();
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));

CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "testWithLoop");
Expand All @@ -61,13 +61,13 @@ public void testInLoop() throws Exception {
public void testOnClassWithJavaObjects() throws Exception {

/*
Test that the MethodGeneratorAmplifier amplifier is able to generate, and manage Collection and Map from java.util
Test that the MethodAdderOnExistingObjectsAmplifier amplifier is able to generate, and manage Collection and Map from java.util
*/

final String packageName = "fr.inria.statementadd";
final Factory factory = Utils.getFactory();
RandomHelper.setSeedRandom(32L);
MethodGeneratorAmplifier amplifier = new MethodGeneratorAmplifier();
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));

CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "test");
Expand Down Expand Up @@ -97,7 +97,7 @@ public void testStatementAddOnArrayObjects() throws Exception {
final String packageName = "fr.inria.statementaddarray";
final Factory factory = Utils.getFactory();
RandomHelper.setSeedRandom(32L);
MethodGeneratorAmplifier amplifier = new MethodGeneratorAmplifier();
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));

CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
Expand Down Expand Up @@ -128,7 +128,7 @@ public void testStatementAddOnUnderTest() throws Exception {
CtClass<Object> ctClass = factory.Class().get("fr.inria.mutation.ClassUnderTestTest");
RandomHelper.setSeedRandom(23L);

MethodGeneratorAmplifier amplifier = new MethodGeneratorAmplifier();
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(ctClass);

CtMethod originalMethod = Utils.findMethod(ctClass, "testLit");
Expand Down Expand Up @@ -166,7 +166,7 @@ public void testStatementAdd() throws Exception {
final String packageName = "fr.inria.statementadd";
final Factory factory = Utils.getFactory();
RandomHelper.setSeedRandom(42L);
MethodGeneratorAmplifier amplifier = new MethodGeneratorAmplifier();
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".TestClassTargetAmplify"));

CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* [email protected]
* on 12/7/16
*/
public class TestMethodCallAdderTest extends AbstractTest {
public class TestMethodCallAdder extends AbstractTest {

@Test
public void testMethodCallAddOnInvocationWithCast() {
Expand All @@ -30,7 +30,7 @@ In case of the invocation has type cast(s), we need to remove them.

CtClass<Object> testClass = Utils.getFactory().Class().get("fr.inria.mutation.ClassUnderTestTest");

TestMethodCallAdder methodCallAdder = new TestMethodCallAdder();
MethodDuplicationAmplifier methodCallAdder = new MethodDuplicationAmplifier();
methodCallAdder.reset(testClass);

final CtMethod<?> originalMethod = testClass.getMethods().stream().filter(m -> "testWithCast".equals(m.getSimpleName())).findFirst().get();
Expand All @@ -48,7 +48,7 @@ public void testMethodCallAddAll() throws Exception {

CtClass<Object> testClass = Utils.getFactory().Class().get("fr.inria.mutation.ClassUnderTestTest");

TestMethodCallAdder methodCallAdder = new TestMethodCallAdder();
MethodDuplicationAmplifier methodCallAdder = new MethodDuplicationAmplifier();
methodCallAdder.reset(testClass);

final CtMethod<?> originalMethod = testClass.getMethods().stream().filter(m -> "testAddCall".equals(m.getSimpleName())).findFirst().get();
Expand All @@ -70,7 +70,7 @@ public void testMethodCallAddAll() throws Exception {
@Test
public void testAddInIf() throws Exception {
CtClass<Object> testClass = Utils.getFactory().Class().get("fr.inria.mutation.ClassUnderTestTest");
TestMethodCallAdder methodCallAdder = new TestMethodCallAdder();
MethodDuplicationAmplifier methodCallAdder = new MethodDuplicationAmplifier();
methodCallAdder.reset(testClass);
final CtMethod<?> originalMethod = Utils.findMethod(testClass, "testWithIf");
final Stream<CtMethod<?>> amplify = methodCallAdder.amplify(originalMethod, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import eu.stamp_project.AbstractTest;
import eu.stamp_project.Utils;
import eu.stamp_project.dspot.amplifier.MethodGeneratorAmplifier;
import eu.stamp_project.dspot.amplifier.MethodAdderOnExistingObjectsAmplifier;
import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.utils.AmplificationHelper;
import eu.stamp_project.utils.program.InputConfiguration;
Expand Down Expand Up @@ -210,7 +210,7 @@ public void testNoInstrumentationOnGeneratedObject() throws Exception {

final String packageName = "fr.inria.statementaddarray";
final Factory factory = Utils.getFactory();
MethodGeneratorAmplifier amplifier = new MethodGeneratorAmplifier();
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));

CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import eu.stamp_project.AbstractTest;
import eu.stamp_project.Utils;
import eu.stamp_project.dspot.amplifier.IterationDecoratorAmplifier;
import eu.stamp_project.dspot.amplifier.MethodGeneratorAmplifier;
import eu.stamp_project.dspot.amplifier.MethodAdderOnExistingObjectsAmplifier;
import eu.stamp_project.dspot.amplifier.NumberLiteralAmplifier;
import eu.stamp_project.dspot.amplifier.ReturnValueAmplifier;
import eu.stamp_project.test_framework.TestFramework;
import eu.stamp_project.utils.program.InputConfiguration;
import eu.stamp_project.utils.AmplificationHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -35,7 +34,7 @@ public void setUp() throws Exception {
InputConfiguration.get().setAmplifiers(
Arrays.asList(
new IterationDecoratorAmplifier(new ReturnValueAmplifier(), 3),
new IterationDecoratorAmplifier(new MethodGeneratorAmplifier(), 2),
new IterationDecoratorAmplifier(new MethodAdderOnExistingObjectsAmplifier(), 2),
new NumberLiteralAmplifier()
)
);
Expand Down

0 comments on commit 7469c84

Please sign in to comment.