edu.rice.cs.drjava.model.junit
Class JUnitTestManager

java.lang.Object
  extended by edu.rice.cs.drjava.model.junit.JUnitTestManager

public class JUnitTestManager
extends Object

Runs in the InterpreterJVM. Runs tests given a classname and formats the results into a (serializable) array of JUnitError that can be passed back to the MainJVM.

Version:
$Id: JUnitTestManager.java 5437 2011-08-05 03:48:19Z rcartwright $

Field Summary
private  JUnitModelCallback _jmc
          The interface to the master JVM via RMI.
private  Lambda<ClassLoader,ClassLoader> _loaderFactory
          A factory producing a ClassLoader for tests with the given parent
protected static Log _log
           
private  TestSuite _suite
          The accumulated test suite; null if no test is pending.
private  List<String> _testClassNames
          The accumulated list of names of TestCase classes; null if no test is pending.
private  List<File> _testFiles
          The list of files corresponding to testClassNames; null if no test is pending.
private  JUnitTestRunner _testRunner
          The current testRunner; initially null.
 
Constructor Summary
JUnitTestManager(JUnitModelCallback jmc, Lambda<ClassLoader,ClassLoader> loaderFactory)
          Standard constructor
 
Method Summary
private  boolean _isJUnitTest(Class<?> c)
          Determines if the given class is a junit Test.
private  int _lineNumber(String sw, String classname)
          Parses the line number out of the stack trace in the given class name.
private  JUnitError _makeJUnitError(TestFailure failure, List<String> classNames, boolean isError, List<File> files)
          Constructs a new JUnitError from a TestFailure
private  void _reset()
           
 List<String> findTestClasses(List<String> classNames, List<File> files)
          Find the test classes among the given classNames and accumulate them in TestSuite for junit.
private  JUnitTestRunner makeRunner()
          Make a fresh JUnitTestRunner with its own class loader instance.
 boolean runTestSuite()
          Runs the pending test suite set up by the preceding call to findTestClasses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

protected static final Log _log

_jmc

private final JUnitModelCallback _jmc
The interface to the master JVM via RMI.


_loaderFactory

private final Lambda<ClassLoader,ClassLoader> _loaderFactory
A factory producing a ClassLoader for tests with the given parent


_testRunner

private JUnitTestRunner _testRunner
The current testRunner; initially null. Each test suite requires a new runner.


_suite

private TestSuite _suite
The accumulated test suite; null if no test is pending.


_testClassNames

private List<String> _testClassNames
The accumulated list of names of TestCase classes; null if no test is pending.


_testFiles

private List<File> _testFiles
The list of files corresponding to testClassNames; null if no test is pending.

Constructor Detail

JUnitTestManager

public JUnitTestManager(JUnitModelCallback jmc,
                        Lambda<ClassLoader,ClassLoader> loaderFactory)
Standard constructor

Method Detail

findTestClasses

public List<String> findTestClasses(List<String> classNames,
                                    List<File> files)
Find the test classes among the given classNames and accumulate them in TestSuite for junit. Returns null if a test suite is already pending.

Parameters:
classNames - the class names that are test class candidates
files - the files corresponding to classNames

runTestSuite

public boolean runTestSuite()
Runs the pending test suite set up by the preceding call to findTestClasses. Runs in a single auxiliary thread, so no need for explicit synchronization.

Returns:
false if no test suite (even an empty one) has been set up

_reset

private void _reset()

_isJUnitTest

private boolean _isJUnitTest(Class<?> c)
Determines if the given class is a junit Test.

Parameters:
c - the class to check
Returns:
true iff the given class is an instance of junit.framework.Test

_makeJUnitError

private JUnitError _makeJUnitError(TestFailure failure,
                                   List<String> classNames,
                                   boolean isError,
                                   List<File> files)
Constructs a new JUnitError from a TestFailure

Parameters:
failure - A given TestFailure
classNames - The classes that were used for this test suite
isError - The passed TestFailure may signify either an error or a failure
files - The files that were used for this test suite
Returns:
JUnitError

_lineNumber

private int _lineNumber(String sw,
                        String classname)
Parses the line number out of the stack trace in the given class name.


makeRunner

private JUnitTestRunner makeRunner()
Make a fresh JUnitTestRunner with its own class loader instance.