use of org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader in project evosuite by EvoSuite.
the class InstrumentingClassLoaderTest method testInnerClasses.
@Ignore
@Test
public void testInnerClasses() throws Exception {
Class<? extends InnerClassesTestSubject> originalClass = InnerClassesTestSubject.class;
Properties.TARGET_CLASS = originalClass.getName();
Properties.PROJECT_PREFIX = originalClass.getPackage().getName();
TestabilityTransformationClassLoader instrumentingClassLoader = new TestabilityTransformationClassLoader();
Class<?> changedClass = instrumentingClassLoader.loadClass(InnerClassesTestSubject.class.getName());
Assert.assertEquals(instrumentingClassLoader, changedClass.getClassLoader());
Assert.assertTrue(changedClass.hashCode() != originalClass.hashCode());
InnerClassesTestSubject original = originalClass.newInstance();
Assert.assertEquals("abcd", original.toString());
Object modified = changedClass.newInstance();
Assert.assertEquals("abcd", modified.toString());
}
use of org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader in project evosuite by EvoSuite.
the class TestUtil method loadInstrumented.
public static Object loadInstrumented(String className, Object... constructorArgs) {
try {
Properties.TARGET_CLASS = className;
Properties.PROJECT_PREFIX = getPrefix(className);
Properties.TARGET_CLASS_PREFIX = Properties.PROJECT_PREFIX;
TestabilityTransformationClassLoader classLoader = new TestabilityTransformationClassLoader();
Class<?> factsComparatorClass = classLoader.loadClass(className);
Class<?>[] argClasses = getArgClasses(constructorArgs);
Constructor<?> factsComparatorConstructor = factsComparatorClass.getConstructor(argClasses);
Object target = factsComparatorConstructor.newInstance(constructorArgs);
return target;
} catch (Exception exc) {
throw new RuntimeException(exc);
}
}
use of org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader in project evosuite by EvoSuite.
the class InstrumentingClassLoaderTest method testDirectInstrumentation.
@Ignore
@Test
public void testDirectInstrumentation() throws Exception {
Class<?> originalClass = ClassLoaderTestSubject.class;
Properties.TARGET_CLASS = originalClass.getName();
Properties.PROJECT_PREFIX = originalClass.getPackage().getName();
ClassLoaderTestSubject original = new ClassLoaderTestSubject();
ExecutionTracer.enable();
ExecutionTracer.getExecutionTracer().clear();
original.assess(6);
ExecutionTrace execTrace = ExecutionTracer.getExecutionTracer().getTrace();
Assert.assertTrue(execTrace.getTrueDistances().isEmpty());
Assert.assertTrue(execTrace.getFalseDistances().isEmpty());
TestabilityTransformationClassLoader instrumentingClassLoader = new TestabilityTransformationClassLoader();
Class<?> changedClass = instrumentingClassLoader.loadClass(ClassLoaderTestSubject.class.getName());
Assert.assertEquals(instrumentingClassLoader, changedClass.getClassLoader());
Assert.assertTrue(changedClass.hashCode() != originalClass.hashCode());
Assert.assertFalse(changedClass.equals(originalClass));
Object changed = changedClass.getConstructor().newInstance();
try {
@SuppressWarnings("unused") ClassLoaderTestSubject casted = (ClassLoaderTestSubject) changed;
Assert.fail();
} catch (ClassCastException exc) {
// expected
}
ExecutionTracer.getExecutionTracer().clear();
TestUtil.invokeMethod(changed, "assess", Integer.valueOf(6));
execTrace = ExecutionTracer.getExecutionTracer().getTrace();
Assert.assertFalse(execTrace.getTrueDistances().isEmpty());
Assert.assertFalse(execTrace.getFalseDistances().isEmpty());
ExecutionTracer.getExecutionTracer().clear();
}
use of org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader in project evosuite by EvoSuite.
the class InstrumentingClassLoaderTest method testDependingInstrumentation.
/*
* Tests the child-first/parent-last property of the classloader.
*/
@Ignore
@Test
public void testDependingInstrumentation() throws Exception {
Class<?> originalClass = DependentClassLoaderTestSubject.class;
Properties.TARGET_CLASS = originalClass.getName();
Properties.PROJECT_PREFIX = originalClass.getPackage().getName();
Properties.TARGET_CLASS_PREFIX = Properties.PROJECT_PREFIX;
TestabilityTransformationClassLoader instrumentingClassLoader = new TestabilityTransformationClassLoader();
Class<?> changedClass = instrumentingClassLoader.loadClass(ClassLoaderTestSubject.class.getName());
Assert.assertEquals(instrumentingClassLoader, changedClass.getClassLoader());
Object changed = changedClass.getConstructor().newInstance();
ExecutionTracer.enable();
ExecutionTracer.getExecutionTracer().clear();
TestUtil.invokeMethod(changed, "trySomethingElse");
ExecutionTrace execTrace = ExecutionTracer.getExecutionTracer().getTrace();
execTrace = ExecutionTracer.getExecutionTracer().getTrace();
Assert.assertFalse(execTrace.getTrueDistances().isEmpty());
Assert.assertFalse(execTrace.getFalseDistances().isEmpty());
ExecutionTracer.getExecutionTracer().clear();
}
use of org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader in project evosuite by EvoSuite.
the class ClassTransformer method instrumentClass.
public Class<?> instrumentClass(String fullyQualifiedTargetClass) {
Class<?> result = instrumentedClasses.get(fullyQualifiedTargetClass);
if (result != null) {
assert Properties.TARGET_CLASS.equals(fullyQualifiedTargetClass);
assert Properties.PROJECT_PREFIX.equals(fullyQualifiedTargetClass);
return result;
}
try {
Properties.TARGET_CLASS = fullyQualifiedTargetClass;
Properties.PROJECT_PREFIX = fullyQualifiedTargetClass;
ExecutionTracer.enable();
ClassLoader classLoader = new TestabilityTransformationClassLoader();
result = classLoader.loadClass(fullyQualifiedTargetClass);
instrumentedClasses.put(fullyQualifiedTargetClass, result);
return result;
} catch (ClassNotFoundException exc) {
throw new RuntimeException(exc);
}
}
Aggregations