renaming and moving
This commit is contained in:
parent
b85037666a
commit
7bd69290c4
37 changed files with 454 additions and 505 deletions
|
|
@ -5,8 +5,8 @@ repositories{
|
|||
mavenCentral()
|
||||
}
|
||||
|
||||
sourceCompatibility = "1.6"
|
||||
targetCompatibility = "1.6"
|
||||
sourceCompatibility = "1.8"
|
||||
targetCompatibility = "1.8"
|
||||
|
||||
sourceSets {
|
||||
test {
|
||||
|
|
@ -23,7 +23,7 @@ dependencies{
|
|||
compile 'javassist:javassist:3.12.1.GA'
|
||||
compile 'com.thoughtworks.xstream:xstream:1.4.7'
|
||||
compile 'org.mockito:mockito-all:1.9.5'
|
||||
testCompile 'junit:junit:4.11'
|
||||
testCompile 'org.jacoco:org.jacoco.core:0.7.1.201405082137'
|
||||
compile 'org.jacoco:org.jacoco.core:0.7.1.201405082137'
|
||||
|
||||
testCompile 'junit:junit:4.11'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
package nl.jssl.autounit;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* record: records in and outputs
|
||||
*
|
||||
* assertUnchangedBehaviour: raises an error when recorded inputs do no lead to
|
||||
* recorded outputs
|
||||
*/
|
||||
public class AutoTester {
|
||||
ResultsWriter resultsWriter = new ResultsWriter();
|
||||
|
||||
public Map<String, MethodCallResults> record(Class<?> instance) {
|
||||
Map<String, MethodCallResults> results = new Recorder(instance).record();
|
||||
resultsWriter.write(instance.getName(), results);
|
||||
return results;
|
||||
}
|
||||
|
||||
private Map<String, MethodCallResults> load(String classname) {
|
||||
try {
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(classname + ".dat"));
|
||||
Map<String, MethodCallResults> results = (Map<String, MethodCallResults>) objectInputStream.readObject();
|
||||
objectInputStream.close();
|
||||
return results;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ public class Configuration {
|
|||
public static ClassPool getClassPool() {
|
||||
ClassPool classPool = new ClassPool();
|
||||
try {
|
||||
classPool.appendClassPath("c:\\workspaces\\autounit\\autounit\\bin");
|
||||
classPool.appendClassPath("bin");
|
||||
} catch (NotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
package nl.jssl.autounit;
|
||||
@SuppressWarnings("serial")
|
||||
public class ExecutionException extends RuntimeException {
|
||||
|
||||
public ExecutionException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ExecutionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public ExecutionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ExecutionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ExecutionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
54
src/main/java/nl/jssl/autounit/JUnitTestCreator.java
Normal file
54
src/main/java/nl/jssl/autounit/JUnitTestCreator.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package nl.jssl.autounit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import nl.jssl.autounit.classanalyser.ClassAnalyser;
|
||||
import nl.jssl.autounit.results.JUnitSourceWriter;
|
||||
|
||||
/**
|
||||
* Creates a Junit source file
|
||||
*
|
||||
*/
|
||||
public class JUnitTestCreator {
|
||||
|
||||
private static final String SOURCEDIRECTORY = "src/outcome/java/";
|
||||
|
||||
public void assembleJUnitTest(Class<?> type) {
|
||||
try {
|
||||
tryAssembleJUnitTest(type);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void tryAssembleJUnitTest(Class<?> type) throws FileNotFoundException {
|
||||
writeSourceFile(createPackageDirectory(type), type);
|
||||
}
|
||||
|
||||
private void writeSourceFile(File packageDirectory, Class<?> classUnderTest) throws FileNotFoundException {
|
||||
resultsWriter(packageDirectory, classUnderTest).write(new ClassAnalyser(classUnderTest).analyse());
|
||||
}
|
||||
|
||||
private JUnitSourceWriter resultsWriter(File packageDirectory, Class<?> type) throws FileNotFoundException {
|
||||
return new JUnitSourceWriter(
|
||||
new PrintStream(new FileOutputStream(toSourceFile(packageDirectory, type))));
|
||||
}
|
||||
|
||||
private File createPackageDirectory(Class<?> type) {
|
||||
File packageDirectory = toPackageDirectory(type);
|
||||
packageDirectory.mkdirs();
|
||||
return packageDirectory;
|
||||
}
|
||||
|
||||
private File toSourceFile(File packageDirectory, Class<?> type) {
|
||||
return new File(packageDirectory, type.getName().replaceAll("\\.", "/") + "Tests.java");
|
||||
}
|
||||
|
||||
private File toPackageDirectory(Class<?> type) {
|
||||
return new File(SOURCEDIRECTORY + type.getPackage().getName().replaceAll("\\.", "/"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
package nl.jssl.autounit;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import nl.jssl.autounit.utils.Permuter.Tuple;
|
||||
|
||||
/**
|
||||
* voert 1 methode uit met wisselende input parameters en bewaart het resultaat.
|
||||
*
|
||||
*/
|
||||
public class MethodcallExecutor {
|
||||
private Object instrumentedTestTarget;
|
||||
private Method m;
|
||||
CoverageAnalyser coverageAnalyser = new CoverageAnalyser();
|
||||
private MethodCallResults result;
|
||||
|
||||
public MethodcallExecutor(Class<?> testClass, Method m) {
|
||||
super();
|
||||
this.instrumentedTestTarget = coverageAnalyser.instrument(testClass);
|
||||
this.m = m;
|
||||
this.result = new MethodCallResults(instrumentedTestTarget, m);
|
||||
}
|
||||
|
||||
public MethodCallResults execute(List<Tuple> inputs) {
|
||||
int missedLines = Integer.MAX_VALUE;
|
||||
InvocationResult lastInvocationResult = null, previous = null;
|
||||
for (Tuple input : inputs) {
|
||||
previous = lastInvocationResult;
|
||||
lastInvocationResult = analyseMethodCall(m, input);
|
||||
int missedCount = lastInvocationResult.coverage.getLineCounter().getMissedCount();
|
||||
if (missedCount < missedLines) { // coverage increases, this is an
|
||||
// interesting input
|
||||
missedLines = missedCount;
|
||||
result.addResult(input, lastInvocationResult.output);
|
||||
}
|
||||
if (missedCount == 0) { // coverage = 100%: done
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastInvocationResult != null) {
|
||||
if (previous == null) {
|
||||
result.setCoverageResult(lastInvocationResult.coverage);
|
||||
} else {
|
||||
result.setCoverageResult(previous.coverage);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private InvocationResult analyseMethodCall(Method m, Tuple input) {
|
||||
Object[] argumentarray = input.toArray();
|
||||
for (int i = 0; i < argumentarray.length; i++) {
|
||||
if (argumentarray[i].toString().equals("autounit:[NULL]")) {
|
||||
argumentarray[i] = null;
|
||||
}
|
||||
}
|
||||
return coverageAnalyser.analyse(instrumentedTestTarget, m, argumentarray);
|
||||
}
|
||||
|
||||
public MethodCallResults getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package nl.jssl.autounit;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class Player {
|
||||
final private Object testinstance;
|
||||
|
||||
private Player(Object testinstance) {
|
||||
super();
|
||||
this.testinstance = testinstance;
|
||||
}
|
||||
|
||||
public void playback(Map<String, List<MethodCallResults>> recordedResults) {
|
||||
for (Entry<String, List<MethodCallResults>> entry: recordedResults.entrySet()) {
|
||||
getInputs(entry.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void getInputs(List<MethodCallResults> value) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package nl.jssl.autounit;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import nl.jssl.autounit.inputs.MethodcallArgumentsFactory;
|
||||
import nl.jssl.autounit.utils.Permuter.Tuple;
|
||||
|
||||
public class Recorder {
|
||||
private Class<?> testTarget;
|
||||
|
||||
public Recorder(Class<?> testTarget) {
|
||||
this.testTarget = testTarget;
|
||||
}
|
||||
|
||||
public Map<String, MethodCallResults> record() {
|
||||
Map<String, MethodCallResults> classresults = new HashMap<String, MethodCallResults>();
|
||||
for (Method m : getPublicMethods()) {
|
||||
MethodCallResults methodresults = recordMethod(m);
|
||||
classresults.put(getMethodSignature(m), methodresults);
|
||||
}
|
||||
return classresults;
|
||||
}
|
||||
|
||||
private String getMethodSignature(Method m) {
|
||||
String signature = Modifier.toString(m.getModifiers()) + " " + m.getReturnType().getName() + " " + m.getName()
|
||||
+ "(";
|
||||
int index = 1;
|
||||
Class<?>[] parameterTypes = m.getParameterTypes();
|
||||
for (Class<?> type : parameterTypes) {
|
||||
signature += type.getName() + " arg" + (index++);
|
||||
if (index <= parameterTypes.length) {
|
||||
signature += ",";
|
||||
}
|
||||
}
|
||||
signature += ")";
|
||||
return signature;
|
||||
}
|
||||
|
||||
private MethodCallResults recordMethod(Method m) {
|
||||
List<Tuple> inputSet = new MethodcallArgumentsFactory().getInputs(testTarget, m);
|
||||
MethodcallExecutor methodcallExecutor = new MethodcallExecutor(testTarget, m);
|
||||
methodcallExecutor.execute(inputSet);
|
||||
return methodcallExecutor.getResult();
|
||||
}
|
||||
|
||||
List<Method> getPublicMethods() {
|
||||
List<Method> publicMethods = new ArrayList<Method>();
|
||||
for (Method m : testTarget.getDeclaredMethods()) {
|
||||
if (Modifier.isPublic(m.getModifiers())) {
|
||||
publicMethods.add(m);
|
||||
}
|
||||
}
|
||||
return publicMethods;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package nl.jssl.autounit;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import nl.jssl.autounit.utils.Permuter.Tuple;
|
||||
import nl.jssl.autounit.utils.XStreamArgumentsConverter;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
public class ResultsWriter {
|
||||
XStream xstream = new XStream();
|
||||
|
||||
public ResultsWriter() {
|
||||
setup();
|
||||
}
|
||||
|
||||
private void setup() {
|
||||
xstream.alias("case", InAndOutput.class);
|
||||
xstream.alias("results", MethodCallResults.class);
|
||||
xstream.alias("args", Tuple.class);
|
||||
|
||||
xstream.registerConverter(new XStreamArgumentsConverter());
|
||||
}
|
||||
|
||||
public void write(String classname, Map<String, MethodCallResults> results) {
|
||||
try {
|
||||
xstream.toXML(results, new FileOutputStream(classname + ".xml"));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package nl.jssl.autounit.classanalyser;
|
||||
@SuppressWarnings("serial")
|
||||
public class AnalysisFailed extends RuntimeException {
|
||||
|
||||
public AnalysisFailed() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AnalysisFailed(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public AnalysisFailed(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public AnalysisFailed(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public AnalysisFailed(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package nl.jssl.autounit.classanalyser;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.jssl.autounit.inputs.MethodcallArgumentsFactory;
|
||||
import nl.jssl.autounit.util.Pair;
|
||||
|
||||
public class ClassAnalyser {
|
||||
private Class<?> testTarget;
|
||||
|
||||
public ClassAnalyser(Class<?> testTarget) {
|
||||
this.testTarget = testTarget;
|
||||
}
|
||||
|
||||
public ClassResults analyse() {
|
||||
List<MethodCallResults> classresults = new ArrayList<>();
|
||||
for (Method m : getPublicMethods()) {
|
||||
MethodCallResults methodresults = recordMethod(m);
|
||||
classresults.add(methodresults);
|
||||
}
|
||||
|
||||
return new ClassResults(testTarget, classresults);
|
||||
}
|
||||
|
||||
private MethodCallResults recordMethod(Method m) {
|
||||
List<Pair> inputSet = new MethodcallArgumentsFactory().getInputs(testTarget, m);
|
||||
MethodcallExecutor methodcallExecutor = new MethodcallExecutor(testTarget, m);
|
||||
methodcallExecutor.execute(inputSet);
|
||||
MethodCallResults mcr = methodcallExecutor.getResult();
|
||||
return mcr;
|
||||
}
|
||||
|
||||
List<Method> getPublicMethods() {
|
||||
List<Method> publicMethods = new ArrayList<Method>();
|
||||
for (Method m : testTarget.getDeclaredMethods()) {
|
||||
if (Modifier.isPublic(m.getModifiers())) {
|
||||
publicMethods.add(m);
|
||||
}
|
||||
}
|
||||
return publicMethods;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,15 +1,12 @@
|
|||
package nl.jssl.autounit;
|
||||
package nl.jssl.autounit.classanalyser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import nl.jssl.autounit.utils.MemoryClassloader;
|
||||
import nl.jssl.autounit.utils.SilentObjectCreator;
|
||||
|
||||
import org.jacoco.core.analysis.Analyzer;
|
||||
import org.jacoco.core.analysis.CoverageBuilder;
|
||||
import org.jacoco.core.analysis.IClassCoverage;
|
||||
import org.jacoco.core.data.ExecutionDataStore;
|
||||
import org.jacoco.core.data.SessionInfoStore;
|
||||
import org.jacoco.core.instr.Instrumenter;
|
||||
|
|
@ -17,6 +14,9 @@ import org.jacoco.core.runtime.IRuntime;
|
|||
import org.jacoco.core.runtime.LoggerRuntime;
|
||||
import org.jacoco.core.runtime.RuntimeData;
|
||||
|
||||
import nl.jssl.autounit.util.MemoryClassloader;
|
||||
import nl.jssl.autounit.util.SilentObjectCreator;
|
||||
|
||||
public class CoverageAnalyser {
|
||||
private IRuntime runtime;
|
||||
private RuntimeData data = new RuntimeData();
|
||||
|
|
@ -50,22 +50,34 @@ public class CoverageAnalyser {
|
|||
Object output = invoke(instrumentedTestTarget, inputs, instanceMethod);
|
||||
|
||||
// jacoco stuff
|
||||
ExecutionDataStore executionData = new ExecutionDataStore();
|
||||
SessionInfoStore sessionInfos = new SessionInfoStore();
|
||||
data.collect(executionData, sessionInfos, false);
|
||||
ExecutionDataStore executionData = executionData();
|
||||
|
||||
runtime.shutdown();
|
||||
|
||||
CoverageBuilder coverageBuilder = new CoverageBuilder();
|
||||
Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
|
||||
String targetName = instrumentedTestTarget.getClass().getName();
|
||||
analyzer.analyzeClass(getTargetClass(targetName), targetName);
|
||||
CoverageBuilder coverageBuilder = coverageBuilder(instrumentedTestTarget, executionData);
|
||||
|
||||
return new InvocationResult(coverageBuilder.getClasses().iterator().next(), output);
|
||||
} catch (Exception e) {
|
||||
throw new ExecutionException(e);
|
||||
throw new AnalysisFailed(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ExecutionDataStore executionData() {
|
||||
ExecutionDataStore executionData = new ExecutionDataStore();
|
||||
SessionInfoStore sessionInfos = new SessionInfoStore();
|
||||
data.collect(executionData, sessionInfos, false);
|
||||
return executionData;
|
||||
}
|
||||
|
||||
private <T> CoverageBuilder coverageBuilder(T instrumentedTestTarget, ExecutionDataStore executionData)
|
||||
throws IOException {
|
||||
CoverageBuilder coverageBuilder = new CoverageBuilder();
|
||||
Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
|
||||
String targetName = instrumentedTestTarget.getClass().getName();
|
||||
analyzer.analyzeClass(getTargetClass(targetName), targetName);
|
||||
return coverageBuilder;
|
||||
}
|
||||
|
||||
private <T> Method getInstrumentedMethod(T testTarget, Method method) throws NoSuchMethodException {
|
||||
return testTarget.getClass().getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||
}
|
||||
|
|
@ -75,29 +87,23 @@ public class CoverageAnalyser {
|
|||
try {
|
||||
output = newInstanceMethod.invoke(testTarget, inputs);
|
||||
} catch (InvocationTargetException i) {
|
||||
StackTraceElement stacktraceElement = i.getTargetException().getStackTrace()[0];
|
||||
String info = stacktraceElement.getClassName() + ":" + stacktraceElement.getLineNumber();
|
||||
output = i.getTargetException().getClass().getName() + "(" + i.getTargetException().getMessage() + ") at "
|
||||
+ info;
|
||||
output = createOutputFromException(i);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private Object createOutputFromException(InvocationTargetException i) {
|
||||
Object output;
|
||||
StackTraceElement stacktraceElement = i.getTargetException().getStackTrace()[0];
|
||||
String info = stacktraceElement.getClassName() + ":" + stacktraceElement.getLineNumber();
|
||||
output = i.getTargetException().getClass().getName() + "(" + i.getTargetException().getMessage() + ") at "
|
||||
+ info;
|
||||
return output;
|
||||
}
|
||||
|
||||
private InputStream getTargetClass(String name) {
|
||||
String resource = '/' + name.replace('.', '/') + ".class";
|
||||
return getClass().getResourceAsStream(resource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class InvocationResult {
|
||||
public final IClassCoverage coverage;
|
||||
public final Object output;
|
||||
|
||||
public InvocationResult(IClassCoverage coverage, Object output) {
|
||||
super();
|
||||
this.coverage = coverage;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,15 +1,17 @@
|
|||
package nl.jssl.autounit;
|
||||
package nl.jssl.autounit.classanalyser;
|
||||
|
||||
import nl.jssl.autounit.util.Pair;
|
||||
|
||||
public class InAndOutput {
|
||||
private final Object input;
|
||||
private final Pair input;
|
||||
private final Object output;
|
||||
|
||||
public InAndOutput(Object input, Object output) {
|
||||
public InAndOutput(Pair input, Object output) {
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public Object getInput() {
|
||||
public Pair getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
package nl.jssl.autounit;
|
||||
package nl.jssl.autounit.classanalyser;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jacoco.core.analysis.IClassCoverage;
|
||||
|
||||
public class MethodCallResults {
|
||||
import nl.jssl.autounit.util.Pair;
|
||||
|
||||
public class MethodCallResults implements Comparable<MethodCallResults> {
|
||||
private transient Object testinstance;
|
||||
private transient Method executedMethod;
|
||||
private List<InAndOutput> contents = new ArrayList<InAndOutput>();
|
||||
|
|
@ -18,7 +21,7 @@ public class MethodCallResults {
|
|||
this.executedMethod = m;
|
||||
}
|
||||
|
||||
public void addResult(Object input, Object output) {
|
||||
public void addResult(Pair input, Object output) {
|
||||
contents.add(new InAndOutput(input, output));
|
||||
}
|
||||
|
||||
|
|
@ -54,4 +57,36 @@ public class MethodCallResults {
|
|||
}
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public String getMethodSignature() {
|
||||
return getMethodSignature(executedMethod);
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return executedMethod.getName();
|
||||
}
|
||||
|
||||
private String getMethodSignature(Method m) {
|
||||
String signature = Modifier.toString(m.getModifiers()) + " " + m.getReturnType().getName() + " " + m.getName()
|
||||
+ "(";
|
||||
int index = 1;
|
||||
Class<?>[] parameterTypes = m.getParameterTypes();
|
||||
for (Class<?> type : parameterTypes) {
|
||||
signature += type.getName() + " arg" + (index++);
|
||||
if (index <= parameterTypes.length) {
|
||||
signature += ",";
|
||||
}
|
||||
}
|
||||
signature += ")";
|
||||
return signature;
|
||||
}
|
||||
|
||||
public Class<?> getMethodReturnType() {
|
||||
return executedMethod.getReturnType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MethodCallResults o) {
|
||||
return getMethodName().compareTo(o.getMethodName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package nl.jssl.autounit.classanalyser;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import nl.jssl.autounit.util.Pair;
|
||||
|
||||
/**
|
||||
* voert 1 methode uit met wisselende input parameters en bewaart het resultaat.
|
||||
*
|
||||
*/
|
||||
public class MethodcallExecutor {
|
||||
private Object instrumentedTestTarget;
|
||||
private Method methodUnderTest;
|
||||
CoverageAnalyser coverageAnalyser = new CoverageAnalyser();
|
||||
private MethodCallResults result;
|
||||
|
||||
public MethodcallExecutor(Class<?> testClass, Method methodUnderTest) {
|
||||
super();
|
||||
this.instrumentedTestTarget = coverageAnalyser.instrument(testClass);
|
||||
this.methodUnderTest = methodUnderTest;
|
||||
this.result = new MethodCallResults(instrumentedTestTarget, methodUnderTest);
|
||||
}
|
||||
|
||||
public MethodCallResults execute(List<Pair> inputs) {
|
||||
InvocationResult lastInvocationResult = null, previous = null;
|
||||
|
||||
int missedLines = Integer.MAX_VALUE;
|
||||
for (Pair input : inputs) {
|
||||
previous = lastInvocationResult;
|
||||
|
||||
lastInvocationResult = analyseMethodCall(methodUnderTest, input);
|
||||
|
||||
int missedCount = lastInvocationResult.getCoverage().getLineCounter().getMissedCount();
|
||||
|
||||
missedLines = addInOutputCombinationWhenCoverageIncreases(missedLines, lastInvocationResult, input,
|
||||
missedCount);
|
||||
|
||||
if (fullyCoveraged(missedCount)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastInvocationResult != null) {
|
||||
if (previous == null) {
|
||||
result.setCoverageResult(lastInvocationResult.getCoverage());
|
||||
} else {
|
||||
result.setCoverageResult(previous.getCoverage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int addInOutputCombinationWhenCoverageIncreases(int missedLines, InvocationResult lastInvocationResult,
|
||||
Pair input, int missedCount) {
|
||||
if (coverageHasIncreased(missedLines, missedCount)) {
|
||||
missedLines = missedCount;
|
||||
addInterestingInAndOutput(input, lastInvocationResult);
|
||||
}
|
||||
return missedLines;
|
||||
}
|
||||
|
||||
private void addInterestingInAndOutput(Pair input, InvocationResult lastInvocationResult) {
|
||||
result.addResult(input, lastInvocationResult.getOutput());
|
||||
}
|
||||
|
||||
private boolean fullyCoveraged(int missedCount) {
|
||||
return missedCount == 0;
|
||||
}
|
||||
|
||||
private boolean coverageHasIncreased(int missedLines, int missedCount) {
|
||||
return missedCount < missedLines;
|
||||
}
|
||||
|
||||
private InvocationResult analyseMethodCall(Method methodUnderTest, Pair input) {
|
||||
Object[] inputs = replaceNullIndicatorWithNull(input.toArray());
|
||||
|
||||
return coverageAnalyser.analyse(instrumentedTestTarget, methodUnderTest, inputs);
|
||||
}
|
||||
|
||||
private Object[] replaceNullIndicatorWithNull(Object[] argumentarray) {
|
||||
for (int i = 0; i < argumentarray.length; i++) {
|
||||
if (argumentarray[i].toString().equals("autounit:[NULL]")) {
|
||||
argumentarray[i] = null;
|
||||
}
|
||||
}
|
||||
return argumentarray;
|
||||
}
|
||||
|
||||
public MethodCallResults getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,14 +9,14 @@ import java.util.Map;
|
|||
|
||||
import nl.jssl.autounit.inputs.objects.ObjectArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.objects.StringArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primtives.ArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primtives.BooleanArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primtives.ByteArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primtives.DoubleArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primtives.FloatArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primtives.IntegerArgumentFactory;
|
||||
import nl.jssl.autounit.utils.Permuter;
|
||||
import nl.jssl.autounit.utils.Permuter.Tuple;
|
||||
import nl.jssl.autounit.inputs.primitives.ArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primitives.BooleanArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primitives.ByteArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primitives.DoubleArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primitives.FloatArgumentFactory;
|
||||
import nl.jssl.autounit.inputs.primitives.IntegerArgumentFactory;
|
||||
import nl.jssl.autounit.util.Pair;
|
||||
import nl.jssl.autounit.util.Permuter;
|
||||
|
||||
public class MethodcallArgumentsFactory {
|
||||
private final Map<Class<?>, ArgumentFactory<?>> primitivesFactories;
|
||||
|
|
@ -26,11 +26,11 @@ public class MethodcallArgumentsFactory {
|
|||
populateFactories();
|
||||
}
|
||||
|
||||
public List<Tuple> getInputs(Class<?> testTarget, Method m) {
|
||||
public List<Pair> getInputs(Class<?> testTarget, Method m) {
|
||||
return combine(getArgumentsForAllParameters(testTarget, m));
|
||||
}
|
||||
|
||||
private List<Tuple> combine(List<List<?>> inputSetsForAllArguments) {
|
||||
private List<Pair> combine(List<List<?>> inputSetsForAllArguments) {
|
||||
int nrOfParameters = inputSetsForAllArguments.size();
|
||||
if (nrOfParameters == 0) {
|
||||
return Collections.emptyList();
|
||||
|
|
@ -42,13 +42,13 @@ public class MethodcallArgumentsFactory {
|
|||
}
|
||||
}
|
||||
|
||||
private List<Tuple> makeArgumentsForSingleParameterCall(List<List<?>> generatedInputSetsForAllArguments) {
|
||||
List<Tuple> allPossibleArguments = new ArrayList<Tuple>();
|
||||
private List<Pair> makeArgumentsForSingleParameterCall(List<List<?>> generatedInputSetsForAllArguments) {
|
||||
List<Pair> allPossibleArguments = new ArrayList<>();
|
||||
|
||||
List<?> generatedInputs = generatedInputSetsForAllArguments.iterator().next();
|
||||
|
||||
for (Object variable : generatedInputs) {
|
||||
Tuple argument = new Tuple(variable);
|
||||
Pair argument = new Pair(variable);
|
||||
allPossibleArguments.add(argument);
|
||||
}
|
||||
return allPossibleArguments;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package nl.jssl.autounit.inputs.objects;
|
|||
|
||||
import javassist.ClassPool;
|
||||
import nl.jssl.autounit.inputs.ArgumentsForSingleParameter;
|
||||
import nl.jssl.autounit.inputs.primtives.ArgumentFactory;
|
||||
import nl.jssl.autounit.utils.ConstantpoolReader;
|
||||
import nl.jssl.autounit.inputs.primitives.ArgumentFactory;
|
||||
import nl.jssl.autounit.util.ConstantpoolReader;
|
||||
|
||||
/**
|
||||
* Creates Strings as arguments for a method call. Uses bytecode analysis to scan the class-under-test for "interesting"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.inputs.primtives;
|
||||
package nl.jssl.autounit.inputs.primitives;
|
||||
|
||||
import nl.jssl.autounit.inputs.ArgumentsForSingleParameter;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.inputs.primtives;
|
||||
package nl.jssl.autounit.inputs.primitives;
|
||||
|
||||
import nl.jssl.autounit.inputs.ArgumentsForSingleParameter;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.inputs.primtives;
|
||||
package nl.jssl.autounit.inputs.primitives;
|
||||
|
||||
import nl.jssl.autounit.inputs.ArgumentsForSingleParameter;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.inputs.primtives;
|
||||
package nl.jssl.autounit.inputs.primitives;
|
||||
|
||||
import nl.jssl.autounit.inputs.ArgumentsForSingleParameter;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.inputs.primtives;
|
||||
package nl.jssl.autounit.inputs.primitives;
|
||||
|
||||
import nl.jssl.autounit.inputs.ArgumentsForSingleParameter;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.inputs.primtives;
|
||||
package nl.jssl.autounit.inputs.primitives;
|
||||
|
||||
import nl.jssl.autounit.inputs.ArgumentsForSingleParameter;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.inputs.primtives;
|
||||
package nl.jssl.autounit.inputs.primitives;
|
||||
|
||||
import nl.jssl.autounit.inputs.ArgumentsForSingleParameter;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.utils;
|
||||
package nl.jssl.autounit.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.utils;
|
||||
package nl.jssl.autounit.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
36
src/main/java/nl/jssl/autounit/util/Permuter.java
Normal file
36
src/main/java/nl/jssl/autounit/util/Permuter.java
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package nl.jssl.autounit.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Makes permutations of n lists of m elements, ie:
|
||||
*
|
||||
* [A,B], [1,2] => [A,1], [A,2], [B,1], [B,2]
|
||||
*/
|
||||
public class Permuter {
|
||||
|
||||
public static List<Pair> permute(List<List<?>> elements) {
|
||||
if (elements.size() >= 2) {
|
||||
List<Pair> result = permutePairs(elements.remove(0), elements.remove(0));
|
||||
|
||||
for (List<?> element : elements) {
|
||||
result = permutePairs(element, result);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
throw new IllegalArgumentException("need at least 2");
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Pair> permutePairs(List<?> list1, List<?> list2) {
|
||||
List<Pair> pairs = new ArrayList<Pair>();
|
||||
for (Object element1 : list1) {
|
||||
for (Object element2 : list2) {
|
||||
pairs.add(new Pair(element1, element2));
|
||||
}
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package nl.jssl.autounit.utils;
|
||||
package nl.jssl.autounit.util;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
package nl.jssl.autounit.utils;
|
||||
|
||||
import nl.jssl.autounit.utils.Permuter.Tuple;
|
||||
package nl.jssl.autounit.util;
|
||||
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
|
|
@ -12,11 +10,11 @@ public class XStreamArgumentsConverter implements Converter {
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public boolean canConvert(Class clazz) {
|
||||
return (clazz == Tuple.class);
|
||||
return (clazz == Pair.class);
|
||||
}
|
||||
|
||||
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
Tuple arguments = (Tuple) value;
|
||||
Pair arguments = (Pair) value;
|
||||
int index = 1;
|
||||
for (Object arg : arguments) {
|
||||
writer.startNode("arg" + index);
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
package nl.jssl.autounit.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Makes permutations of n lists of m elements, ie:
|
||||
*
|
||||
* [A,B], [1,2] => [A,1], [A,2], [B,1], [B,2]
|
||||
*/
|
||||
public class Permuter {
|
||||
|
||||
public static List<Tuple> permute(List<List<?>> elements) {
|
||||
if (elements.size() >= 2) {
|
||||
List<Tuple> result = permutePairs(elements.remove(0), elements.remove(0));
|
||||
|
||||
for (List<?> element : elements) {
|
||||
result = permutePairs(element, result);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
throw new IllegalArgumentException("need at least 2");
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Tuple> permutePairs(List<?> list1, List<?> list2) {
|
||||
List<Tuple> pairs = new ArrayList<Tuple>();
|
||||
for (Object element1 : list1) {
|
||||
for (Object element2 : list2) {
|
||||
pairs.add(new Tuple(element1, element2));
|
||||
}
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public static class Tuple implements Iterable<Object> {
|
||||
public final Object element1;
|
||||
public final Object element2;
|
||||
|
||||
public Tuple(Object element1) {
|
||||
this.element1 = element1;
|
||||
this.element2 = null;
|
||||
}
|
||||
|
||||
public Tuple(Object element1, Object element2) {
|
||||
super();
|
||||
this.element1 = element1;
|
||||
this.element2 = element2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Object> iterator() {
|
||||
return asList().iterator();
|
||||
}
|
||||
|
||||
private List<Object> asList() {
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
if (element1 != null) {
|
||||
add(element1, list);
|
||||
} else {
|
||||
add("autounit:[NULL]", list);
|
||||
}
|
||||
if (element2 != null) {
|
||||
add(element2, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void add(Object element, List<Object> list) {
|
||||
if (!(element instanceof Tuple)) {
|
||||
list.add(element);
|
||||
} else {
|
||||
Tuple pair = (Tuple) element;
|
||||
add(pair.element1, list);
|
||||
add(pair.element2, list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String string = "";
|
||||
for (Object o : this) {
|
||||
string += o.toString() + "-";
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return asList().toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
package nl.jssl.autounit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import nl.jssl.autounit.testclasses.BooleanArguments;
|
||||
import nl.jssl.autounit.testclasses.ByteArguments;
|
||||
import nl.jssl.autounit.testclasses.FloatArguments;
|
||||
import nl.jssl.autounit.testclasses.IntArguments;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PrimtiveTypeTests {
|
||||
@Test
|
||||
public void testGetPublicMethods() throws NoSuchMethodException, SecurityException {
|
||||
List<Method> publicMethods = new Recorder(IntArguments.class).getPublicMethods();
|
||||
|
||||
assertEquals(2, publicMethods.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegerArgument() {
|
||||
Map<String, MethodCallResults> results = new AutoTester().record(IntArguments.class);
|
||||
Set<String> keys = results.keySet();
|
||||
assertTrue(keys.contains("public java.lang.String evenOrUneven(int arg1,int arg2)"));
|
||||
MethodCallResults mcr = results.values().iterator().next();
|
||||
System.out.println(mcr.getCoverageResult().getLineCounter().getMissedCount() + " missed lines");
|
||||
System.out.println(mcr.getReport());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanArgument() {
|
||||
Map<String, MethodCallResults> results = new AutoTester().record(BooleanArguments.class);
|
||||
Set<String> keys = results.keySet();
|
||||
assertTrue(keys.contains("public java.lang.String getText(boolean arg1,boolean arg2)"));
|
||||
MethodCallResults mcr = results.values().iterator().next();
|
||||
System.out.println(mcr.getCoverageResult().getLineCounter().getMissedCount() + " missed lines");
|
||||
System.out.println(mcr.getReport());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteArgument() {
|
||||
Map<String, MethodCallResults> results = new AutoTester().record(ByteArguments.class);
|
||||
Set<String> keys = results.keySet();
|
||||
assertTrue(keys.contains("public int getDouble(byte arg1)"));
|
||||
MethodCallResults mcr = results.values().iterator().next();
|
||||
System.out.println(mcr.getCoverageResult().getLineCounter().getMissedCount() + " missed lines");
|
||||
System.out.println(mcr.getReport());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatArgument() {
|
||||
Map<String, MethodCallResults> results = new AutoTester().record(FloatArguments.class);
|
||||
Set<String> keys = results.keySet();
|
||||
assertTrue(keys.contains("public int round(float arg1)"));
|
||||
MethodCallResults mcr = results.values().iterator().next();
|
||||
System.out.println(mcr.getCoverageResult().getLineCounter().getMissedCount() + " missed lines");
|
||||
System.out.println(mcr.getReport());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package nl.jssl.autounit.classanalyser;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import nl.jssl.autounit.testclasses.BooleanArguments;
|
||||
import nl.jssl.autounit.testclasses.ByteArguments;
|
||||
import nl.jssl.autounit.testclasses.FloatArguments;
|
||||
import nl.jssl.autounit.testclasses.IntArguments;
|
||||
|
||||
public class PrimtiveTypeTests {
|
||||
@Test
|
||||
public void testGetPublicMethods() throws NoSuchMethodException, SecurityException {
|
||||
List<Method> publicMethods = new ClassAnalyser(IntArguments.class).getPublicMethods();
|
||||
|
||||
assertEquals(2, publicMethods.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegerArgument() {
|
||||
Iterator<MethodCallResults> methodCallResults = new TreeSet<>(
|
||||
new ClassAnalyser(IntArguments.class).analyse().getMethodCallResults()).iterator();
|
||||
|
||||
assertEquals("public java.lang.String evenOrUneven(int arg1,int arg2)",
|
||||
methodCallResults.next().getMethodSignature());
|
||||
assertEquals("public int randomOther(int arg1)", methodCallResults.next().getMethodSignature());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanArgument() {
|
||||
MethodCallResults mcr = new ClassAnalyser(BooleanArguments.class).analyse().getMethodCallResults().get(0);
|
||||
assertEquals(mcr.getMethodSignature(), "public java.lang.String getText(boolean arg1,boolean arg2)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteArgument() {
|
||||
MethodCallResults mcr = new ClassAnalyser(ByteArguments.class).analyse().getMethodCallResults().get(0);
|
||||
assertEquals(mcr.getMethodSignature(), "public int getDouble(byte arg1)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatArgument() {
|
||||
MethodCallResults mcr = new ClassAnalyser(FloatArguments.class).analyse().getMethodCallResults().get(0);
|
||||
assertEquals(mcr.getMethodSignature(), "public int round(float arg1)");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,23 +1,21 @@
|
|||
package nl.jssl.autounit;
|
||||
package nl.jssl.autounit.classanalyser;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import nl.jssl.autounit.testclasses.StringArguments;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import nl.jssl.autounit.testclasses.StringArguments;
|
||||
|
||||
public class StringTypeTests {
|
||||
|
||||
@Test
|
||||
public void testStringArgumentShouldBeTjeempie() {
|
||||
Map<String, MethodCallResults> results = new AutoTester().record(StringArguments.class);
|
||||
Set<String> keys = results.keySet();
|
||||
String methodSignature = keys.iterator().next();
|
||||
List<MethodCallResults> results = new ClassAnalyser(StringArguments.class).analyse().getMethodCallResults();
|
||||
MethodCallResults mcr = results.get(0);
|
||||
String methodSignature = mcr.getMethodSignature();
|
||||
assertEquals("public boolean getBar(java.lang.String arg1)", methodSignature);
|
||||
MethodCallResults mcr = results.values().iterator().next();
|
||||
System.out.println(mcr.getCoverageResult().getLineCounter().getMissedCount() + " missed lines");
|
||||
System.out.println(mcr.getReport());
|
||||
}
|
||||
|
|
@ -28,7 +26,8 @@ public class StringTypeTests {
|
|||
// Map<String, MethodCallResults> results = new
|
||||
// AutoTester().record(MethodSignatureMaker.class);
|
||||
// Set<String> keys = results.keySet();
|
||||
// assertTrue(keys.contains("public java.lang.String getMethodSignature(java.lang.reflect.Method arg1)"));
|
||||
// assertTrue(keys.contains("public java.lang.String
|
||||
// getMethodSignature(java.lang.reflect.Method arg1)"));
|
||||
// MethodCallResults mcr = results.values().iterator().next();
|
||||
// System.out.println(mcr.getCoverageResult().getLineCounter().getMissedCount()
|
||||
// + " missed lines");
|
||||
|
|
@ -1,23 +1,28 @@
|
|||
package nl.jssl.autounit.inputs.objects;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import nl.jssl.autounit.AutoTester;
|
||||
import nl.jssl.autounit.MethodCallResults;
|
||||
import nl.jssl.autounit.testclasses.SomeBean;
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import nl.jssl.autounit.classanalyser.ClassAnalyser;
|
||||
import nl.jssl.autounit.classanalyser.MethodCallResults;
|
||||
import nl.jssl.autounit.testclasses.SomeBean;
|
||||
|
||||
public class JavaBeanTests {
|
||||
@Test
|
||||
public void testJavaBeanArgument() {
|
||||
Map<String, MethodCallResults> results = new AutoTester().record(SomeBean.class);
|
||||
Set<String> keys = results.keySet();
|
||||
Assert.assertTrue(keys.contains("public void setFoo(java.lang.String arg1)"));
|
||||
MethodCallResults mcr = results.values().iterator().next();
|
||||
System.out.println(mcr.getCoverageResult().getLineCounter().getMissedCount() + " missed lines");
|
||||
System.out.println(mcr.getReport());
|
||||
Iterator<MethodCallResults> results = getSortedAnalysisResults().iterator();
|
||||
|
||||
assertEquals("public int getBar()", results.next().getMethodSignature());
|
||||
assertEquals("public java.lang.String getFoo()", results.next().getMethodSignature());
|
||||
assertEquals("public void setBar(int arg1)", results.next().getMethodSignature());
|
||||
assertEquals("public void setFoo(java.lang.String arg1)", results.next().getMethodSignature());
|
||||
}
|
||||
|
||||
private TreeSet<MethodCallResults> getSortedAnalysisResults() {
|
||||
return new TreeSet<>(new ClassAnalyser(SomeBean.class).analyse().getMethodCallResults());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@ package nl.jssl.autounit.inspect;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.NotFoundException;
|
||||
import nl.jssl.autounit.testclasses.IntArguments;
|
||||
import nl.jssl.autounit.utils.ConstantpoolReader;
|
||||
|
||||
import org.junit.Test;
|
||||
import nl.jssl.autounit.util.ConstantpoolReader;
|
||||
|
||||
public class ConstantpoolReaderTest {
|
||||
@Test
|
||||
public void test() throws NotFoundException {
|
||||
ClassPool classPool = new ClassPool();
|
||||
classPool.appendClassPath("c:\\workspaces\\autounit\\autounit\\bin");
|
||||
classPool.appendClassPath("bin");
|
||||
ConstantpoolReader reader = new ConstantpoolReader(classPool);
|
||||
List<String> strings = reader.scanStrings(IntArguments.class);
|
||||
for (String string : strings) {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,6 @@ import static org.junit.Assert.assertEquals;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.jssl.autounit.utils.Permuter;
|
||||
import nl.jssl.autounit.utils.Permuter.Tuple;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PermuterTests {
|
||||
|
|
@ -16,13 +13,16 @@ public class PermuterTests {
|
|||
List<Integer> integers = new ArrayList<Integer>();
|
||||
integers.add(1);
|
||||
integers.add(2);
|
||||
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.add("A");
|
||||
strings.add("B");
|
||||
|
||||
List<List<?>> outer = new ArrayList<List<?>>();
|
||||
outer.add(integers);
|
||||
outer.add(strings);
|
||||
List<Tuple> permuted = Permuter.permute(outer);
|
||||
List<Pair> permuted = Permuter.permute(outer);
|
||||
|
||||
assertEquals("1-A-", permuted.get(0).toString());
|
||||
assertEquals("1-B-", permuted.get(1).toString());
|
||||
assertEquals("2-A-", permuted.get(2).toString());
|
||||
|
|
@ -46,7 +46,7 @@ public class PermuterTests {
|
|||
outer.add(strings);
|
||||
outer.add(vogons);
|
||||
|
||||
List<Tuple> permuted = Permuter.permute(outer);
|
||||
List<Pair> permuted = Permuter.permute(outer);
|
||||
assertEquals("Vogon Jeltz-1-A-", permuted.get(0).toString());
|
||||
assertEquals("Vogon Jeltz-1-B-", permuted.get(1).toString());
|
||||
assertEquals("Vogon Jeltz-2-A-", permuted.get(2).toString());
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ public class MyMethod {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public Class getReturnType() {
|
||||
public Class<?> getReturnType() {
|
||||
return Void.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue