/
AmplificationTest.java
62 lines (54 loc) · 2.34 KB
/
AmplificationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package fr.inria.diversify.dspot;
import eu.stamp.project.testrunner.runner.test.TestListener;
import fr.inria.AbstractTest;
import fr.inria.Utils;
import org.junit.Test;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.factory.Factory;
import java.util.Arrays;
import java.util.Collections;
import static fr.inria.diversify.utils.AmplificationHelper.prepareTestMethod;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Created by Benjamin DANGLOT
* benjamin.danglot@inria.fr
* on 09/05/18
*/
public class AmplificationTest extends AbstractTest {
@Test
public void compileAndRunTest() throws Exception {
/*
Test that the Amplification can run AbstractTestClass.
The amplification will use ALL the implementation of the AbstractTestClass
*/
final Amplification amplification = new Amplification(
Utils.getInputConfiguration(),
Collections.emptyList(),
null,
Utils.getCompiler()
);
final CtClass testClass = Utils.findClass("fr.inria.inheritance.Inherited");
final TestListener testListener = amplification.compileAndRunTestsNoFail(testClass,
Arrays.asList(Utils.findMethod(testClass, "test"), Utils.findMethod(testClass, "test2"))
);
assertNotNull(testListener);
assertTrue(testListener.getFailingTests().isEmpty());
assertEquals(4, testListener.getRunningTests().size());
assertEquals(4, testListener.getPassingTests().size());
}
/**
* Tests that original test annotations are kept and modified correctly.
*/
@Test
public void prepareTestMethodTest() throws Exception {
CtMethod testMethodWithAnnotations = ((CtMethod) (Utils.findClass("fr.inria.filter.passing.PassingTest").getMethodsByName("testNPEExpected").get(0)));
final Factory factory = testMethodWithAnnotations.getFactory();
prepareTestMethod(testMethodWithAnnotations, factory);
// expected was kept and timeout was increased
assertEquals("[@org.junit.Test(timeout = 10000, expected = java.lang.NullPointerException.class)]",
testMethodWithAnnotations.getAnnotations().toString());
}
}