本文整理汇总了Java中spoon.reflect.declaration.CtClass类的典型用法代码示例。如果您正苦于以下问题:Java CtClass类的具体用法?Java CtClass怎么用?Java CtClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtClass类属于spoon.reflect.declaration包,在下文中一共展示了CtClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runJBSE
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
public static List<Map<String, List<String>>> runJBSE(String classpath, CtMethod<?> testMethod) {
final RunParameters p = new RunParameters();
p.addClasspath(addRequiredJARsToClasspath(classpath).split(":"));
p.setMethodSignature(
testMethod.getParent(CtClass.class).getQualifiedName().replaceAll("\\.", "/"),
methodToDescriptor.apply(testMethod),
testMethod.getSimpleName()
);
p.setDecisionProcedureType(RunParameters.DecisionProcedureType.Z3);
p.setExternalDecisionProcedurePath("lib/z3/build/bin/z3");
p.setOutputFileName("out/runIf_z3.txt");
p.setStepShowMode(RunParameters.StepShowMode.LEAVES);
p.setStateFormatMode(RunParameters.StateFormatMode.FULLTEXTHISTORY);
p.setShowOnConsole(Main.verbose);
final Run r = new Run(p);
r.run();
return filterDistinctLeaves(StateFormatterTextWithHistory.getStates())
.stream()
.map(JBSERunner::buildConditionsOnArguments)
.collect(Collectors.toList());
}
示例2: test
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void test() throws Exception {
this.configuration.getInputProgram().setFactory(this.launcher.getFactory());
final Ex2Amplifier amplifier = new Ex2Amplifier(this.configuration);
final CtClass<?> testClass = this.launcher.getFactory().Class().get("fr.inria.calculator.CalculatorTest");
amplifier.reset(testClass);
final List<CtMethod> amplifiedTestAccumulate = amplifier.apply(testClass.getMethodsByName("testAccumulate").get(0));
assertEquals(2, amplifiedTestAccumulate.size());
final String expectedAmplifiedTestMethod = "{" + AmplificationHelper.LINE_SEPARATOR +
" final Calculator calculator1 = new Calculator(0);" + AmplificationHelper.LINE_SEPARATOR +
" Assert.assertEquals((-5), calculator1.getCurrentValue());" + AmplificationHelper.LINE_SEPARATOR +
" calculator1.accumulate((-5));" + AmplificationHelper.LINE_SEPARATOR +
" Assert.assertEquals((-15), calculator1.getCurrentValue());" + AmplificationHelper.LINE_SEPARATOR +
"}";
assertEquals(expectedAmplifiedTestMethod, amplifiedTestAccumulate.get(0).getBody().toString());
}
示例3: testLauncherOnTestThatUseSystemProperties
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testLauncherOnTestThatUseSystemProperties() throws Exception {
/*
Contract: DSpot is able to run a test that use System Properties.
System Properties must be described in the properties file given as input.
System Properties must be described with the key systemProperties (i.e. systemProperties=...)
System Properties must be a couple of key and value, separated by an equals '=' (e.g. key=value)
System Properties must be separated by a comma ',' (e.g. key1=value1,key2=value2)
*/
Utils.init("src/test/resources/sample/sample.properties");
final CtClass aClass = Utils.findClass("fr.inria.systemproperties.SystemPropertiesTest");
final String classPath = AmplificationHelper.getClassPath(Utils.getCompiler(), Utils.getInputProgram());
final TestListener run = TestLauncher.run(Utils.getInputConfiguration(), classPath, aClass);
assertEquals(1, run.getPassingTests().size());
assertEquals(1, run.getRunningTests().size());
assertEquals(0, run.getFailingTests().size());
assertTrue(run.getFailingTests().isEmpty());
}
示例4: testLauncherOnTestUsingReflectiveTestRunnerOnTestThatUseSystemProperty
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testLauncherOnTestUsingReflectiveTestRunnerOnTestThatUseSystemProperty() throws Exception {
/*
Using the ReflectiveTestRunner
*/
TestRunnerFactory.useReflectiveTestRunner = true;
Utils.init("src/test/resources/sample/sample.properties");
final CtClass aClass = Utils.findClass("fr.inria.systemproperties.SystemPropertiesTest");
final String classPath = AmplificationHelper.getClassPath(Utils.getCompiler(), Utils.getInputProgram());
final TestListener run = TestLauncher.run(Utils.getInputConfiguration(), classPath, aClass);
assertEquals(1, run.getPassingTests().size());
assertEquals(1, run.getRunningTests().size());
assertEquals(0, run.getFailingTests().size());
assertTrue(run.getFailingTests().isEmpty());
TestRunnerFactory.useReflectiveTestRunner = false;
}
示例5: testPitDescartesMode
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testPitDescartesMode() throws Exception {
assertFalse(MavenPitCommandAndOptions.descartesMode);
MavenPitCommandAndOptions.descartesMode = true;
InputConfiguration configuration = new InputConfiguration("src/test/resources/descartes/descartes.properties");
DSpot dspot = new DSpot(configuration, 1,
new PitMutantScoreSelector("src/test/resources/descartes/mutations.csv"));
final CtClass<Object> originalTestClass = dspot.getInputProgram().getFactory().Class().get("fr.inria.stamp.mutationtest.test.TestCalculator");
assertEquals(2, originalTestClass.getMethods().size());
final CtType ctType = dspot.amplifyTest(
"fr.inria.stamp.mutationtest.test.TestCalculator",
Collections.singletonList("Integraltypestest")
);
// assertTrue(originalTestClass.getMethods().size() < ctType.getMethods().size()); // TODO
FileUtils.cleanDirectory(new File(configuration.getOutputDirectory()));
assertTrue(MavenPitCommandAndOptions.descartesMode);
}
示例6: testDSpotCompiler
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testDSpotCompiler() throws Exception {
final InputProgram inputProgram = getInputProgram();
final DSpotCompiler compiler = DSpotCompiler.createDSpotCompiler(inputProgram, "");
final CtClass<?> aClass = getClass(compiler.getLauncher().getFactory());
final List<CtMethod<?>> compile = TestCompiler.compile(compiler, aClass, "");
assertTrue(compile.isEmpty());
assertEquals(1, aClass.getMethods().size());
final List<CtMethod> tests = new UncompilableAmplifier().apply(aClass.getMethods().stream().findAny().get());
tests.forEach(aClass::addMethod);
assertEquals(3, aClass.getMethods().size());
final CtMethod uncompilableTest = tests.stream()
.filter(ctMethod -> ctMethod.getSimpleName().equals("uncompilableTest"))
.findFirst()
.get();
final List<CtMethod<?>> results = TestCompiler.compile(compiler, aClass, "");
assertEquals(1, results.size());
assertEquals("uncompilableTest", results.get(0).getSimpleName());
assertEquals(uncompilableTest, results.get(0));
// assertEquals(2, aClass.getMethods().size());
assertEquals(3, aClass.getMethods().size());//The compile methods is now stateless: using a clone class
}
示例7: testByteMutation
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testByteMutation() throws Exception {
final String nameMethod = "methodByte";
final byte originalValue = 23;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Byte> expectedValues = Arrays.asList((byte)22, (byte)24, Byte.MIN_VALUE, Byte.MAX_VALUE, (byte)0);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(5, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values",
expectedValues.contains(mutantLiteral.getValue()));
}
}
示例8: testShortMutation
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testShortMutation() throws Exception {
final String nameMethod = "methodShort";
final short originalValue = 23;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Short> expectedValues = Arrays.asList((short)22, (short)24, Short.MIN_VALUE, Short.MAX_VALUE, (short)0);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(5, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values",
expectedValues.contains(mutantLiteral.getValue()));
}
}
示例9: testIntMutation
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testIntMutation() throws Exception {
final String nameMethod = "methodInteger";
final int originalValue = 23;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Integer> expectedValues = Arrays.asList(22, 24, 2147483647, -2147483648, 0);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(5, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values",
expectedValues.contains(mutantLiteral.getValue()));
}
}
示例10: testLongMutation
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testLongMutation() throws Exception {
final String nameMethod = "methodLong";
final long originalValue = 23L;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Long> expectedValues = Arrays.asList(22L, 24L, Long.MIN_VALUE, Long.MAX_VALUE, 0L);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(5, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values",
expectedValues.contains(mutantLiteral.getValue()));
}
}
示例11: testFloatMutation
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testFloatMutation() throws Exception {
final String nameMethod = "methodFloat";
final double originalValue = 23.0F;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Float> expectedValues = Arrays.asList(22.0F, 24.0F, Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_NORMAL,
Float.NaN ,Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY , 0.0F);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(9, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values",
expectedValues.contains(mutantLiteral.getValue()));
}
}
示例12: testDoubleMutation
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testDoubleMutation() throws Exception {
final String nameMethod = "methodDouble";
final double originalValue = 23.0D;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
NumberLiteralAmplifier amplificator = getAmplifier(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<Double> expectedValues = Arrays.asList(22.0D, 24.0D, Double.MAX_VALUE, Double.MIN_VALUE, Double.MIN_NORMAL,
Double.NaN ,Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY , 0.0D);
List<CtMethod> mutantMethods = amplificator.apply(method);
assertEquals(9, mutantMethods.size());
for (int i = 0; i < mutantMethods.size(); i++) {
CtMethod mutantMethod = mutantMethods.get(i);
assertEquals(nameMethod + "litNum" + (i + 1), mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertNotEquals(originalValue, mutantLiteral.getValue());
assertTrue(mutantLiteral.getValue() + " not in expected values",
expectedValues.contains(mutantLiteral.getValue()));
}
}
示例13: testMethodCallRemoveAll
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testMethodCallRemoveAll() throws Exception {
/*
Test that we remove method call in a test for each used method in the test.
3 method are called in the original test, we produce 3 test methods.
*/
CtClass<Object> testClass = Utils.getFactory().Class().get("fr.inria.mutation.ClassUnderTestTest");
TestMethodCallRemover methodCallRemove = new TestMethodCallRemover();
methodCallRemove.reset(null);
final CtMethod<?> originalMethod = testClass.getMethods().stream().filter(m -> "testAddCall".equals(m.getSimpleName())).findFirst().get();
List<CtMethod> amplifiedMethods = methodCallRemove.apply(originalMethod);
assertEquals(2, amplifiedMethods.size());
for (int i = 0; i < amplifiedMethods.size(); i++) {
assertEquals(originalMethod.getBody().getStatements().size() - 1, amplifiedMethods.get(i).getBody().getStatements().size());
assertNotEquals(amplifiedMethods.get((i+1) % amplifiedMethods.size()).getBody(), amplifiedMethods.get(i).getBody());//checks that all generated methods are different
}
}
示例14: testMethodCallRemoveRnd
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testMethodCallRemoveRnd() throws Exception {
/*
Test that we remove method call in a test for each used method in the test.
2 method are called in the original test, we produce 2 test methods randomly among them.
*/
CtClass<Object> testClass = Utils.getFactory().Class().get("fr.inria.mutation.ClassUnderTestTest");
AmplificationHelper.setSeedRandom(23L);
TestMethodCallRemover methodCallRemove = new TestMethodCallRemover();
methodCallRemove.reset(null);
final CtMethod<?> originalMethod = testClass.getMethods().stream().filter(m -> "testAddCall".equals(m.getSimpleName())).findFirst().get();
CtMethod amplifiedMethod = methodCallRemove.applyRandom(originalMethod);
CtMethod amplifiedMethod2 = methodCallRemove.applyRandom(originalMethod);
assertEquals(originalMethod.getBody().getStatements().size() - 1, amplifiedMethod.getBody().getStatements().size());
assertEquals(originalMethod.getBody().getStatements().size() - 1, amplifiedMethod2.getBody().getStatements().size());
assertNotEquals(amplifiedMethod.getBody().getStatements(), amplifiedMethod2.getBody().getStatements());
}
示例15: testBooleanMutation
import spoon.reflect.declaration.CtClass; //导入依赖的package包/类
@Test
public void testBooleanMutation() throws Exception {
/*
Test the amplification on boolean literal
*/
final String nameMethod = "methodBoolean";
final boolean originalValue = true;
CtClass<Object> literalMutationClass = Utils.getFactory().Class().get("fr.inria.amp.LiteralMutation");
AmplificationHelper.setSeedRandom(42L);
TestDataMutator mutator = getTestDataMutator(literalMutationClass);
CtMethod method = literalMutationClass.getMethod(nameMethod);
List<CtMethod> mutantMethods = mutator.apply(method);
CtMethod mutantMethod = mutantMethods.get(0);
assertEquals(1, mutantMethods.size());
assertEquals(nameMethod + SUFFIX_MUTATION + "Boolean" + "1", mutantMethod.getSimpleName());
CtLiteral mutantLiteral = mutantMethod.getBody().getElements(new TypeFilter<>(CtLiteral.class)).get(0);
assertEquals(!(originalValue), mutantLiteral.getValue());
}