org.softevo.ample
Class AmpleTestRunListener

java.lang.Object
  extended by org.softevo.ample.AmpleTestRunListener
All Implemented Interfaces:
org.eclipse.jdt.junit.ITestRunListener

public class AmpleTestRunListener
extends java.lang.Object
implements org.eclipse.jdt.junit.ITestRunListener

JUnit test run listener.

The instance of this class maintains up-to-date lists of passing and failing tests.

The Ample plugin initializes and registers a single instance of this class. It can be accessed by calling the method AmplePlugin.getSharedListener().


Field Summary
private  java.util.ArrayList failingTests
          List of JUnit tests that have failed in assertions or due to exceptions.
private  java.util.ArrayList passingTests
          List of JUnit tests that have passed.
private  boolean testsAreRunning
          Flag indictating that tests are currently running.
 
Fields inherited from interface org.eclipse.jdt.junit.ITestRunListener
STATUS_ERROR, STATUS_FAILURE, STATUS_OK
 
Constructor Summary
AmpleTestRunListener()
          Initializes a new instance of AmpleTestRunListener.
 
Method Summary
private  org.eclipse.jdt.internal.junit.ui.TestRunInfo addTestIfNeeded(java.util.ArrayList aTests, java.lang.String aTestId, java.lang.String aTestName)
          Adds a test to a given list of tests if not already present.
 boolean areTestsRunning()
          Checks if there are tests currently running.
 org.eclipse.jdt.internal.junit.ui.TestRunInfo findFailingTestRun(java.lang.String testId)
          Utility method that searches a failing test with a given id.
 org.eclipse.jdt.internal.junit.ui.TestRunInfo findPassingTestRun(java.lang.String testId)
          Utility method that searches a passing test with a given id.
static org.eclipse.jdt.internal.junit.ui.TestRunInfo findTestRun(java.util.ArrayList runs, java.lang.String testId)
          Utility method that searches a list of runs for a run with a given id.
 org.eclipse.jdt.internal.junit.ui.TestRunInfo getFailingTest(int index)
          Gets the TestRunInfo at the specified position in the list of failing tests.
 java.util.ArrayList getFailingTests()
          Gets the list of failing tests.
 org.eclipse.jdt.internal.junit.ui.TestRunInfo getPassingTest(int index)
          Gets the TestRunInfo at the specified position in the list of passing tests.
 java.util.ArrayList getPassingTests()
          Gets the list of passing tests.
 org.eclipse.jdt.internal.junit.ui.TestRunInfo[] getPassingTests(int[] indices)
          Gets an array of all the specified passing tests.
 int getPassingTestsCount()
          Gets the number of passing tests.
 int indexOfFailing(org.eclipse.jdt.internal.junit.ui.TestRunInfo testInfo)
          Gets the index of the specified failing test.
private  void removeTest(java.util.ArrayList aTests, java.lang.String aTestId)
          Removes a test, if present, from a speicified list of tests.
 void testEnded(java.lang.String testId, java.lang.String testName)
           
 void testFailed(int status, java.lang.String testId, java.lang.String testName, java.lang.String trace)
           
 void testFailed(int status, java.lang.String testId, java.lang.String testName, java.lang.String trace, java.lang.String expected, java.lang.String actual)
           
private  boolean testHasFailed(java.lang.String aTestId)
          Checks if a specified test has failed.
 void testReran(java.lang.String testId, java.lang.String testClass, java.lang.String testName, int status, java.lang.String trace)
           
 void testRunEnded(long elapsedTime)
           
 void testRunStarted(int testCount)
           
 void testRunStopped(long elapsedTime)
           
 void testRunTerminated()
           
 void testStarted(java.lang.String testId, java.lang.String testName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

testsAreRunning

private volatile boolean testsAreRunning
Flag indictating that tests are currently running.


passingTests

private java.util.ArrayList passingTests
List of JUnit tests that have passed.


failingTests

private java.util.ArrayList failingTests
List of JUnit tests that have failed in assertions or due to exceptions.

Constructor Detail

AmpleTestRunListener

public AmpleTestRunListener()
Initializes a new instance of AmpleTestRunListener.

Note: This class is not intended to be instatiated by clients.

Method Detail

testFailed

public void testFailed(int status,
                       java.lang.String testId,
                       java.lang.String testName,
                       java.lang.String trace,
                       java.lang.String expected,
                       java.lang.String actual)

testRunStarted

public void testRunStarted(int testCount)
Specified by:
testRunStarted in interface org.eclipse.jdt.junit.ITestRunListener

testRunEnded

public void testRunEnded(long elapsedTime)
Specified by:
testRunEnded in interface org.eclipse.jdt.junit.ITestRunListener

testRunStopped

public void testRunStopped(long elapsedTime)
Specified by:
testRunStopped in interface org.eclipse.jdt.junit.ITestRunListener

testRunTerminated

public void testRunTerminated()
Specified by:
testRunTerminated in interface org.eclipse.jdt.junit.ITestRunListener

testStarted

public void testStarted(java.lang.String testId,
                        java.lang.String testName)
Specified by:
testStarted in interface org.eclipse.jdt.junit.ITestRunListener

testEnded

public void testEnded(java.lang.String testId,
                      java.lang.String testName)
Specified by:
testEnded in interface org.eclipse.jdt.junit.ITestRunListener

testFailed

public void testFailed(int status,
                       java.lang.String testId,
                       java.lang.String testName,
                       java.lang.String trace)
Specified by:
testFailed in interface org.eclipse.jdt.junit.ITestRunListener

testReran

public void testReran(java.lang.String testId,
                      java.lang.String testClass,
                      java.lang.String testName,
                      int status,
                      java.lang.String trace)
Specified by:
testReran in interface org.eclipse.jdt.junit.ITestRunListener

areTestsRunning

public boolean areTestsRunning()
Checks if there are tests currently running.

Returns:
true if JUnit tests are currently running; false otherwise.

getPassingTestsCount

public int getPassingTestsCount()
Gets the number of passing tests.

Returns:
Number of of passing tests present.

getPassingTests

public java.util.ArrayList getPassingTests()
Gets the list of passing tests.

Returns:
ArrayList of all the passing tests.

getPassingTests

public org.eclipse.jdt.internal.junit.ui.TestRunInfo[] getPassingTests(int[] indices)
Gets an array of all the specified passing tests.

Parameters:
indices - Array of zero-based indices of passing tests in the list of passing tests.
Returns:
Array of TestRunInfo instances corresponding to the given indices.
Throws:
IndexOutOfBoundException - When any of the specified indices is out of range.

getPassingTest

public org.eclipse.jdt.internal.junit.ui.TestRunInfo getPassingTest(int index)
Gets the TestRunInfo at the specified position in the list of passing tests.

This method is used for simplifying the call:
(TestRunInfo) AmplePlugin.getSharedListener().getPassingTests().get(i)
to:
AmplePlugin.getSharedListener().getPassingTest(i)

Parameters:
index - Zero-based index of the test to return.
Returns:
Information on the test at the specified index in the list of passing tests.
Throws:
IndexOutOfBoundException - When specified index is out of range.

getFailingTests

public java.util.ArrayList getFailingTests()
Gets the list of failing tests.

Returns:
ArrayList of all the failing tests.

getFailingTest

public org.eclipse.jdt.internal.junit.ui.TestRunInfo getFailingTest(int index)
Gets the TestRunInfo at the specified position in the list of failing tests.

This method is used for simplifying the call:
(TestRunInfo) AmplePlugin.getSharedListener().getFailingTests().get(i)
to:
AmplePlugin.getSharedListener().getFailingTest(i)

Parameters:
index - Zero-based index of the test to return.
Returns:
Information on the test at the specified index in the list of failing tests.
Throws:
IndexOutOfBoundException - When specified index is out of range.

indexOfFailing

public int indexOfFailing(org.eclipse.jdt.internal.junit.ui.TestRunInfo testInfo)
Gets the index of the specified failing test.

Parameters:
testInfo - Information of the failing test the get the index of.
Returns:
Zero-based index of the given failing test, -1 if the specified test does not belong to the list of failing tests.
See Also:
getFailingTests()

findTestRun

public static org.eclipse.jdt.internal.junit.ui.TestRunInfo findTestRun(java.util.ArrayList runs,
                                                                        java.lang.String testId)
Utility method that searches a list of runs for a run with a given id.

Parameters:
runs - the list of runs to be searched
testId - the id of the sought teset
Returns:
the info object or null if nothing was found

findFailingTestRun

public org.eclipse.jdt.internal.junit.ui.TestRunInfo findFailingTestRun(java.lang.String testId)
Utility method that searches a failing test with a given id.

Parameters:
testId - the id of the sought teset
Returns:
the info object or null if nothing was found

findPassingTestRun

public org.eclipse.jdt.internal.junit.ui.TestRunInfo findPassingTestRun(java.lang.String testId)
Utility method that searches a passing test with a given id.

Parameters:
testId - the id of the sought teset
Returns:
the info object or null if nothing was found

testHasFailed

private boolean testHasFailed(java.lang.String aTestId)
Checks if a specified test has failed.

Parameters:
aTestId - ID of test to verify.
Returns:
true if failingTests contains a test with the specified ID; false otherwise.

removeTest

private void removeTest(java.util.ArrayList aTests,
                        java.lang.String aTestId)
Removes a test, if present, from a speicified list of tests.

Parameters:
aTests - List of tests to be updated.
aTestId - ID of test to be removed.

addTestIfNeeded

private org.eclipse.jdt.internal.junit.ui.TestRunInfo addTestIfNeeded(java.util.ArrayList aTests,
                                                                      java.lang.String aTestId,
                                                                      java.lang.String aTestName)
Adds a test to a given list of tests if not already present.

Parameters:
aTests - List of test to search in.
aTestId - ID of the test to be added.
aTestName - Name of the test to be added.
Returns:
Test with the specified ID as found in (or added to) the given test list.