public class JUnitCreator
extends java.lang.Object
String for a suite of JUnit4 tests.| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
AFTER_ALL
The JUnit annotation for the AfterAll option.
|
private static java.lang.String |
AFTER_ALL_METHOD
The method name for the AfterAll option.
|
private static java.lang.String |
AFTER_EACH
The JUnit annotation for the AfterEach option.
|
private static java.lang.String |
AFTER_EACH_METHOD
The method name for the AfterEach option.
|
private com.github.javaparser.ast.stmt.BlockStmt |
afterAllBody
The Java text for AfterAll method of generated test class.
|
private com.github.javaparser.ast.stmt.BlockStmt |
afterEachBody
The Java text for AfterEach method of generated test class.
|
private static java.lang.String |
BEFORE_ALL
The JUnit annotation for the BeforeAll option.
|
private static java.lang.String |
BEFORE_ALL_METHOD
The method name for the BeforeAll option.
|
private static java.lang.String |
BEFORE_EACH
The JUnit annotation for the BeforeEach option.
|
private static java.lang.String |
BEFORE_EACH_METHOD
The method name for the BeforeEach option.
|
private com.github.javaparser.ast.stmt.BlockStmt |
beforeAllBody
The Java text for BeforeAll method of generated test class.
|
private com.github.javaparser.ast.stmt.BlockStmt |
beforeEachBody
The Java text for BeforeEach method of generated test class.
|
private static java.lang.String |
BOOLEAN_ARRAY_EQUALS_METHOD
The definition of
assertArrayEquals(boolean[], boolean[]). |
private java.util.Map<java.lang.String,java.lang.Integer> |
classMethodCounts
classMethodCounts maps test class names to the number of methods in each class.
|
(package private) static com.github.javaparser.JavaParser |
javaParser
An instance of a Java parser.
|
private java.lang.String |
packageName
The package name.
|
private com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> |
PUBLIC
The "public" modifier.
|
private com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> |
PUBLIC_STATIC
The "public" and "static" modifiers.
|
| Modifier | Constructor and Description |
|---|---|
private |
JUnitCreator(java.lang.String packageName) |
| Modifier and Type | Method and Description |
|---|---|
private void |
addAfterAll(com.github.javaparser.ast.stmt.BlockStmt body)
Add text for AfterClass-annotated method in each generated text class.
|
private void |
addAfterEach(com.github.javaparser.ast.stmt.BlockStmt text)
Add text for After-annotated method in each generated test class.
|
private void |
addBeforeAll(com.github.javaparser.ast.stmt.BlockStmt body)
Add text for BeforeClass-annotated method in each generated test class.
|
private void |
addBeforeEach(com.github.javaparser.ast.stmt.BlockStmt body)
Add text for Before-annotated method in each generated test class.
|
private com.github.javaparser.ast.body.MethodDeclaration |
createFixture(java.lang.String annotation,
com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> modifiers,
java.lang.String methodName,
com.github.javaparser.ast.stmt.BlockStmt body)
Creates the declaration of a single test fixture.
|
com.github.javaparser.ast.CompilationUnit |
createTestClass(java.lang.String testClassName,
NameGenerator methodNameGen,
java.util.List<ExecutableSequence> sequences)
Create a test class.
|
java.lang.String |
createTestDriver(java.lang.String driverName,
java.lang.Iterable<java.lang.String> testClassNames,
int numMethods)
Create non-reflective test driver as a main class.
|
private com.github.javaparser.ast.body.MethodDeclaration |
createTestMethod(java.lang.String className,
java.lang.String methodName,
ExecutableSequence testSequence)
Creates a test method as a
String for the sequence testSequence. |
java.lang.String |
createTestSuite(java.lang.String suiteClassName,
java.lang.Iterable<java.lang.String> testClassNames)
Creates the JUnit4 suite class for the tests in this object as a
String. |
static JUnitCreator |
getTestCreator(java.lang.String junit_package_name,
com.github.javaparser.ast.stmt.BlockStmt beforeAllBody,
com.github.javaparser.ast.stmt.BlockStmt afterAllBody,
com.github.javaparser.ast.stmt.BlockStmt beforeEachBody,
com.github.javaparser.ast.stmt.BlockStmt afterEachBody)
Create a JUnitCreator object.
|
static com.github.javaparser.ast.stmt.BlockStmt |
parseFixture(java.util.List<java.lang.String> bodyText) |
static com.github.javaparser.JavaParser javaParser
private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> PUBLIC
private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> PUBLIC_STATIC
private final java.lang.String packageName
private java.util.Map<java.lang.String,java.lang.Integer> classMethodCounts
private com.github.javaparser.ast.stmt.BlockStmt beforeAllBody
private com.github.javaparser.ast.stmt.BlockStmt afterAllBody
private com.github.javaparser.ast.stmt.BlockStmt beforeEachBody
private com.github.javaparser.ast.stmt.BlockStmt afterEachBody
private static final java.lang.String BEFORE_ALL
private static final java.lang.String AFTER_ALL
private static final java.lang.String BEFORE_EACH
private static final java.lang.String AFTER_EACH
private static final java.lang.String BEFORE_ALL_METHOD
private static final java.lang.String AFTER_ALL_METHOD
private static final java.lang.String BEFORE_EACH_METHOD
private static final java.lang.String AFTER_EACH_METHOD
private static final java.lang.String BOOLEAN_ARRAY_EQUALS_METHOD
assertArrayEquals(boolean[], boolean[]). Needed if Randoop's
generated tests are run under JUnit 4.11 or earlier. JUnit version 4.11 contains assertArrayEquals for other types of arrays, but not for boolean arrays.public static JUnitCreator getTestCreator(java.lang.String junit_package_name, com.github.javaparser.ast.stmt.BlockStmt beforeAllBody, com.github.javaparser.ast.stmt.BlockStmt afterAllBody, com.github.javaparser.ast.stmt.BlockStmt beforeEachBody, com.github.javaparser.ast.stmt.BlockStmt afterEachBody)
junit_package_name - the package name for the generated test classesbeforeAllBody - the Java text for BeforeAll method of generated test classafterAllBody - the Java text for AfterAll method of generated test classbeforeEachBody - the Java text for BeforeEach method of generated test classafterEachBody - the Java text for AfterEach method of generated test classprivate void addBeforeAll(com.github.javaparser.ast.stmt.BlockStmt body)
body - the (Java) text for methodprivate void addAfterAll(com.github.javaparser.ast.stmt.BlockStmt body)
body - the (Java) text for methodprivate void addBeforeEach(com.github.javaparser.ast.stmt.BlockStmt body)
body - the (Java) text for methodprivate void addAfterEach(com.github.javaparser.ast.stmt.BlockStmt text)
text - the (Java) text for methodpublic com.github.javaparser.ast.CompilationUnit createTestClass(java.lang.String testClassName,
NameGenerator methodNameGen,
java.util.List<ExecutableSequence> sequences)
testClassName - the class namemethodNameGen - the generator that creates method namessequences - the contents of the test methodsprivate com.github.javaparser.ast.body.MethodDeclaration createTestMethod(java.lang.String className,
java.lang.String methodName,
ExecutableSequence testSequence)
String for the sequence testSequence.className - the name of the test classmethodName - the name of the test methodtestSequence - the ExecutableSequence test sequenceString for the test methodprivate com.github.javaparser.ast.body.MethodDeclaration createFixture(java.lang.String annotation,
com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> modifiers,
java.lang.String methodName,
com.github.javaparser.ast.stmt.BlockStmt body)
annotation - the fixture annotationmodifiers - the method modifiers for fixture declarationmethodName - the name of the fixture methodbody - the BlockStmt for the fixtureStringpublic java.lang.String createTestSuite(java.lang.String suiteClassName,
java.lang.Iterable<java.lang.String> testClassNames)
String.suiteClassName - the name of the suite class createdtestClassNames - the names of the test classes in the suiteString with the declaration for the suite classpublic java.lang.String createTestDriver(java.lang.String driverName,
java.lang.Iterable<java.lang.String> testClassNames,
int numMethods)
driverName - the name for the driver classtestClassNames - the names of the test classes in the suitenumMethods - the number of methods; used for zero-paddingStringpublic static com.github.javaparser.ast.stmt.BlockStmt parseFixture(java.util.List<java.lang.String> bodyText)
throws com.github.javaparser.ParseException
com.github.javaparser.ParseException