Class JUnitCreator

java.lang.Object
randoop.output.JUnitCreator

public class JUnitCreator extends Object
Creates Java source as String for a suite of JUnit4 tests.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    The JUnit annotation for the AfterAll option.
    private static final String
    The method name for the AfterAll option.
    private static final String
    The JUnit annotation for the AfterEach option.
    private static final String
    The method name for the AfterEach option.
    private com.github.javaparser.ast.stmt.BlockStmt
    The Java text for AfterAll method of generated test class.
    private com.github.javaparser.ast.stmt.BlockStmt
    The Java text for AfterEach method of generated test class.
    private static final String
    The JUnit annotation for the BeforeAll option.
    private static final String
    The method name for the BeforeAll option.
    private static final String
    The JUnit annotation for the BeforeEach option.
    private static final String
    The method name for the BeforeEach option.
    private com.github.javaparser.ast.stmt.BlockStmt
    The Java text for BeforeAll method of generated test class.
    private com.github.javaparser.ast.stmt.BlockStmt
    The Java text for BeforeEach method of generated test class.
    private Map<String,Integer>
    classMethodCounts maps test class names to the number of methods in each class.
    (package private) static com.github.javaparser.JavaParser
    An instance of a Java parser.
    private final String
    The package name.
    private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier>
    The "public" modifier.
    private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier>
    The "public" and "static" modifiers.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    JUnitCreator(String packageName)
     
  • Method Summary

    Modifier and Type
    Method
    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(String annotation, com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> modifiers, String methodName, com.github.javaparser.ast.stmt.BlockStmt body)
    Creates the declaration of a single test fixture.
    com.github.javaparser.ast.CompilationUnit
    createTestClass(String testClassName, NameGenerator methodNameGen, List<ExecutableSequence> sequences)
    Create a test class.
    createTestDriver(String driverName, Iterable<String> testClassNames, int numMethods)
    Create non-reflective test driver as a main class.
    private com.github.javaparser.ast.body.MethodDeclaration
    createTestMethod(String className, String methodName, ExecutableSequence testSequence)
    Creates a test method as a String for the sequence testSequence.
    createTestSuite(String suiteClassName, Iterable<String> testClassNames)
    Creates the JUnit4 suite class for the tests in this object as a String.
    getTestCreator(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)
     
    static com.github.javaparser.ast.stmt.BlockStmt
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • javaParser

      static com.github.javaparser.JavaParser javaParser
      An instance of a Java parser.
    • PUBLIC

      private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> PUBLIC
      The "public" modifier.
    • PUBLIC_STATIC

      private final com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> PUBLIC_STATIC
      The "public" and "static" modifiers.
    • packageName

      private final String packageName
      The package name. May be null, but may not be the empty string.
    • classMethodCounts

      private Map<String,Integer> classMethodCounts
      classMethodCounts maps test class names to the number of methods in each class. This is used to generate lists of method names for a class. Each test method is named TEST_METHOD_NAME_PREFIX+i for some integer i.
    • beforeAllBody

      private com.github.javaparser.ast.stmt.BlockStmt beforeAllBody
      The Java text for BeforeAll method of generated test class.
    • afterAllBody

      private com.github.javaparser.ast.stmt.BlockStmt afterAllBody
      The Java text for AfterAll method of generated test class.
    • beforeEachBody

      private com.github.javaparser.ast.stmt.BlockStmt beforeEachBody
      The Java text for BeforeEach method of generated test class.
    • afterEachBody

      private com.github.javaparser.ast.stmt.BlockStmt afterEachBody
      The Java text for AfterEach method of generated test class.
    • BEFORE_ALL

      private static final String BEFORE_ALL
      The JUnit annotation for the BeforeAll option.
      See Also:
    • AFTER_ALL

      private static final String AFTER_ALL
      The JUnit annotation for the AfterAll option.
      See Also:
    • BEFORE_EACH

      private static final String BEFORE_EACH
      The JUnit annotation for the BeforeEach option.
      See Also:
    • AFTER_EACH

      private static final String AFTER_EACH
      The JUnit annotation for the AfterEach option.
      See Also:
    • BEFORE_ALL_METHOD

      private static final String BEFORE_ALL_METHOD
      The method name for the BeforeAll option.
      See Also:
    • AFTER_ALL_METHOD

      private static final String AFTER_ALL_METHOD
      The method name for the AfterAll option.
      See Also:
    • BEFORE_EACH_METHOD

      private static final String BEFORE_EACH_METHOD
      The method name for the BeforeEach option.
      See Also:
    • AFTER_EACH_METHOD

      private static final String AFTER_EACH_METHOD
      The method name for the AfterEach option.
      See Also:
  • Constructor Details

    • JUnitCreator

      private JUnitCreator(String packageName)
  • Method Details

    • getTestCreator

      public static JUnitCreator getTestCreator(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)
    • addBeforeAll

      private void addBeforeAll(com.github.javaparser.ast.stmt.BlockStmt body)
      Add text for BeforeClass-annotated method in each generated test class.
      Parameters:
      body - the (Java) text for method
    • addAfterAll

      private void addAfterAll(com.github.javaparser.ast.stmt.BlockStmt body)
      Add text for AfterClass-annotated method in each generated text class.
      Parameters:
      body - the (Java) text for method
    • addBeforeEach

      private void addBeforeEach(com.github.javaparser.ast.stmt.BlockStmt body)
      Add text for Before-annotated method in each generated test class.
      Parameters:
      body - the (Java) text for method
    • addAfterEach

      private void addAfterEach(com.github.javaparser.ast.stmt.BlockStmt text)
      Add text for After-annotated method in each generated test class.
      Parameters:
      text - the (Java) text for method
    • createTestClass

      public com.github.javaparser.ast.CompilationUnit createTestClass(String testClassName, NameGenerator methodNameGen, List<ExecutableSequence> sequences)
      Create a test class.
      Parameters:
      testClassName - the class name
      methodNameGen - the generator that creates method names
      sequences - the contents of the test methods
      Returns:
      the CompilationUnit for a test class
    • createTestMethod

      private com.github.javaparser.ast.body.MethodDeclaration createTestMethod(String className, String methodName, ExecutableSequence testSequence)
      Creates a test method as a String for the sequence testSequence.
      Parameters:
      className - the name of the test class
      methodName - the name of the test method
      testSequence - the ExecutableSequence test sequence
      Returns:
      the String for the test method
    • createFixture

      private com.github.javaparser.ast.body.MethodDeclaration createFixture(String annotation, com.github.javaparser.ast.NodeList<com.github.javaparser.ast.Modifier> modifiers, String methodName, com.github.javaparser.ast.stmt.BlockStmt body)
      Creates the declaration of a single test fixture.
      Parameters:
      annotation - the fixture annotation
      modifiers - the method modifiers for fixture declaration
      methodName - the name of the fixture method
      body - the BlockStmt for the fixture
      Returns:
      the fixture method as a String
    • createTestSuite

      public String createTestSuite(String suiteClassName, Iterable<String> testClassNames)
      Creates the JUnit4 suite class for the tests in this object as a String.
      Parameters:
      suiteClassName - the name of the suite class created
      testClassNames - the names of the test classes in the suite
      Returns:
      the String with the declaration for the suite class
    • createTestDriver

      public String createTestDriver(String driverName, Iterable<String> testClassNames, int numMethods)
      Create non-reflective test driver as a main class.
      Parameters:
      driverName - the name for the driver class
      testClassNames - the names of the test classes in the suite
      numMethods - the number of methods; used for zero-padding
      Returns:
      the test driver class as a String
    • parseFixture

      public static com.github.javaparser.ast.stmt.BlockStmt parseFixture(List<String> bodyText) throws com.github.javaparser.ParseException
      Throws:
      com.github.javaparser.ParseException