use of fr.inria.diversify.dspot.selector.json.mutant.TestClassJSON in project dspot by STAMP-project.
the class ExecutedMutantSelector method reportJSONMutants.
private void reportJSONMutants() {
if (this.currentClassTestToBeAmplified == null) {
return;
}
TestClassJSON testClassJSON;
Gson gson = new GsonBuilder().setPrettyPrinting().create();
final File file = new File(this.configuration.getOutputDirectory() + "/" + this.currentClassTestToBeAmplified.getQualifiedName() + "_mutants_executed.json");
if (file.exists()) {
try {
testClassJSON = gson.fromJson(new FileReader(file), TestClassJSON.class);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} else {
testClassJSON = new TestClassJSON(getNbMutantExecutedOriginally(this.currentClassTestToBeAmplified.getQualifiedName()), this.currentClassTestToBeAmplified.getQualifiedName(), this.currentClassTestToBeAmplified.getMethods().stream().filter(AmplificationChecker::isTest).count());
}
List<CtMethod> keys = new ArrayList<>(this.mutantExecutedPerAmplifiedTestMethod.keySet());
keys.forEach(amplifiedTest -> {
List<PitResult> pitResults = new ArrayList<>(this.mutantExecutedPerAmplifiedTestMethod.get(amplifiedTest));
final List<MutantJSON> mutantsJson = new ArrayList<>();
pitResults.forEach(pitResult -> mutantsJson.add(new MutantJSON(pitResult.getFullQualifiedNameMutantOperator(), pitResult.getLineNumber(), pitResult.getNameOfMutatedMethod())));
if (amplifiedTest == null) {
testClassJSON.addTestCase(new TestCaseJSON(this.currentClassTestToBeAmplified.getSimpleName(), Counter.getAllAssertions(), Counter.getAllInput(), mutantsJson));
} else {
testClassJSON.addTestCase(new TestCaseJSON(amplifiedTest.getSimpleName(), Counter.getAssertionOfSinceOrigin(amplifiedTest), Counter.getInputOfSinceOrigin(amplifiedTest), mutantsJson));
}
});
try (FileWriter writer = new FileWriter(file, false)) {
writer.write(gson.toJson(testClassJSON));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of fr.inria.diversify.dspot.selector.json.mutant.TestClassJSON in project dspot by STAMP-project.
the class PitMutantScoreSelector method reportJSONMutants.
private void reportJSONMutants() {
if (this.currentClassTestToBeAmplified == null) {
return;
}
TestClassJSON testClassJSON;
Gson gson = new GsonBuilder().setPrettyPrinting().create();
final File file = new File(this.configuration.getOutputDirectory() + "/" + this.currentClassTestToBeAmplified.getQualifiedName() + "_mutants_killed.json");
if (file.exists()) {
try {
testClassJSON = gson.fromJson(new FileReader(file), TestClassJSON.class);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} else {
testClassJSON = new TestClassJSON(getNbMutantKilledOriginally(this.currentClassTestToBeAmplified.getQualifiedName()), this.currentClassTestToBeAmplified.getQualifiedName(), this.currentClassTestToBeAmplified.getMethods().stream().filter(AmplificationChecker::isTest).count());
}
List<CtMethod> keys = new ArrayList<>(this.testThatKilledMutants.keySet());
keys.forEach(amplifiedTest -> {
List<PitResult> pitResults = new ArrayList<>(this.testThatKilledMutants.get(amplifiedTest));
final List<MutantJSON> mutantsJson = new ArrayList<>();
pitResults.forEach(pitResult -> mutantsJson.add(new MutantJSON(pitResult.getFullQualifiedNameMutantOperator(), pitResult.getLineNumber(), pitResult.getNameOfMutatedMethod())));
if (amplifiedTest == null) {
testClassJSON.addTestCase(new TestCaseJSON(this.currentClassTestToBeAmplified.getSimpleName(), Counter.getAllAssertions(), Counter.getAllInput(), mutantsJson));
} else {
testClassJSON.addTestCase(new TestCaseJSON(amplifiedTest.getSimpleName(), Counter.getAssertionOfSinceOrigin(amplifiedTest), Counter.getInputOfSinceOrigin(amplifiedTest), mutantsJson));
}
});
try (FileWriter writer = new FileWriter(file, false)) {
writer.write(gson.toJson(testClassJSON));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations