Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.batik.test
Class AbstractTest  view AbstractTest download AbstractTest.java

java.lang.Object
  extended byorg.apache.batik.test.AbstractTest
All Implemented Interfaces:
Test
Direct Known Subclasses:
DefaultTestSuite, MemoryLeakTest, ParametrizedTest, PerformanceTest, PerformanceTestValidator, TestReportValidator

public abstract class AbstractTest
extends java.lang.Object
implements Test

Base class containing convenience methods for writing tests.
There are at least three approaches to write new tests derived from AbstractTest:

Here are some examples: public class MyTestA extends AbstractTest { public boolean runImplBase() { if(someConditionFails){ return false; } return true; } } public class MyTestB extends AbstractTest { public TestReport runImpl() { if(someConditionFails){ TestReport report = reportError(MY_ERROR_CODE); report.addDescriptionEntry(ENTRY_KEY_MY_ERROR_DESCRIPTION_KEY, myErrorDescriptionValue); return report; } return reportSuccess(); } public class MyTestC extends AbstractTest { public TestReport runImpl() throws Exception { assertTrue(somCondition); assertEquals(valueA, valueB); assertNull(shouldBeNullRef); if(someErrorCondition){ error(MY_ERROR_CODE); } return reportSuccess(); }

Version:
$Id: AbstractTest.java,v 1.12 2004/08/18 07:16:55 vhardy Exp $

Field Summary
protected  java.lang.String id
          This test's id.
protected  java.lang.String name
          This test's name.
protected  TestSuite parent
          This test's parent, in case this test is part of a suite.
private  DefaultTestReport report
          TestReport
 
Constructor Summary
AbstractTest()
           
 
Method Summary
 void assertEquals(int ref, int cmp)
           
 void assertEquals(java.lang.Object ref, java.lang.Object cmp)
          Convenience method to check for a specific condition.
 void assertNull(java.lang.Object ref)
          Convenience method to check that a reference is null
 void assertTrue(boolean b)
          Convenience method to check that a given boolean is true.
 void error(java.lang.String errorCode)
          Convenience method to report an error condition.
 java.lang.String getId()
          Return this Test's id.
 java.lang.String getName()
          Returns this Test's name.
 TestSuite getParent()
          Returns this Test's parent, in case this Test is part of a TestSuite.
 java.lang.String getQualifiedId()
          Return this Test's qualified id.
 TestReport reportError(java.lang.String errorCode)
          Convenience method to report a simple error code.
 TestReport reportException(java.lang.String errorCode, java.lang.Exception e)
          Convenience method to help implementations report errors.
 TestReport reportSuccess()
          Convenience method.
 TestReport run()
          This default implementation of the run method catches any Exception thrown from the runImpl method and creates a TestReport indicating an internal Test failure when that happens.
 TestReport runImpl()
          Subclasses should implement this method with the content of the test case.
 boolean runImplBasic()
          In the simplest test implementation, developers can simply implement the following method.
 void setId(java.lang.String id)
          Set this Test's id.
 void setName(java.lang.String name)
          Sets this test's name
 void setParent(TestSuite parent)
          Set this Test's parent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected java.lang.String id
This test's id.


parent

protected TestSuite parent
This test's parent, in case this test is part of a suite.


name

protected java.lang.String name
This test's name. If null, the class' name is returned.


report

private DefaultTestReport report
TestReport

Constructor Detail

AbstractTest

public AbstractTest()
Method Detail

getName

public java.lang.String getName()
Returns this Test's name.

Specified by:
getName in interface Test

setName

public void setName(java.lang.String name)
Sets this test's name


getId

public java.lang.String getId()
Return this Test's id.

Specified by:
getId in interface Test

getQualifiedId

public java.lang.String getQualifiedId()
Return this Test's qualified id.

Specified by:
getQualifiedId in interface Test

setId

public void setId(java.lang.String id)
Set this Test's id. Null is not allowed.

Specified by:
setId in interface Test

getParent

public TestSuite getParent()
Description copied from interface: Test
Returns this Test's parent, in case this Test is part of a TestSuite. The returned value may be null.

Specified by:
getParent in interface Test

setParent

public void setParent(TestSuite parent)
Description copied from interface: Test
Set this Test's parent.

Specified by:
setParent in interface Test

run

public TestReport run()
This default implementation of the run method catches any Exception thrown from the runImpl method and creates a TestReport indicating an internal Test failure when that happens. Otherwise, this method simply returns the TestReport generated by the runImpl method.

Specified by:
run in interface Test

runImpl

public TestReport runImpl()
                   throws java.lang.Exception
Subclasses should implement this method with the content of the test case. Typically, implementations will choose to catch and process all exceptions and error conditions they are looking for in the code they exercise but will let exceptions due to their own processing propagate.


runImplBasic

public boolean runImplBasic()
                     throws java.lang.Exception
In the simplest test implementation, developers can simply implement the following method.


reportSuccess

public TestReport reportSuccess()
Convenience method.


reportError

public TestReport reportError(java.lang.String errorCode)
Convenience method to report a simple error code.


error

public void error(java.lang.String errorCode)
           throws TestErrorConditionException
Convenience method to report an error condition.


assertNull

public void assertNull(java.lang.Object ref)
                throws AssertNullException
Convenience method to check that a reference is null


assertTrue

public void assertTrue(boolean b)
                throws AssertTrueException
Convenience method to check that a given boolean is true.


assertEquals

public void assertEquals(java.lang.Object ref,
                         java.lang.Object cmp)
                  throws AssertEqualsException
Convenience method to check for a specific condition. Returns true if both objects are null or if ref is not null and ref.equals(cmp) is true.


assertEquals

public void assertEquals(int ref,
                         int cmp)
                  throws AssertEqualsException

reportException

public TestReport reportException(java.lang.String errorCode,
                                  java.lang.Exception e)
Convenience method to help implementations report errors. An AbstractTest extension will typically catch exceptions for specific error conditions it wants to point out. For example: public TestReport runImpl() throws Exception {
try{
.... something ....
catch(MySpecialException e){
return reportException(MY_SPECIAL_ERROR_CODE, e);
}

public static final String MY_SPECIAL_ERROR_CODE = "myNonQualifiedClassName.my.error.code"


Note that the implementor will also need to add an entry in its Messages.properties file. That file is expected to be in a resource file called Messages having the same package name as the Test class, appended with ".resources".