org.jutil.junit
Class JutilTest

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--junit.framework.TestCase
              |
              +--org.jutil.junit.JutilTest
All Implemented Interfaces:
junit.framework.Test

public abstract class JutilTest
extends junit.framework.TestCase

This is an extension for the junit TestCase class.

This class adds revision checking to junit tests. The revision of a library class is kept in a static string, which is automatically updated by CVS (or another revision control management system). Each testclass passes a Revision object to the constructor of this class, which represents the revision that is tested by that testclass. When the library class is changed, the revisions will differ, and a RevisionError will be thrown. This way a developer knows that he must check whether or not the testclass must be adapted.

At this moment this class can only work with cvs revisions. Put the following code in the library class:


 public final static String CVS_REVISION ="$Revision: 1.9 $";
 

CVS will now automatically adapt the CVS_REVISION field when the cvs revision is changed.

The test class either pass a Class to a constructor to indicated the tested class , or for Jutil.org testclasses, use the constructor which determines the testclass itself. For the Jutil.org testclasses, the following scheme is used:

org.jutiltest.X.TestY -> org.jutil.X.T

A typical constructor of a testclass will look like this:


 super(nameForJunit, new CVSRevision("x.x.x"));
 

Of course any Revision can be passed, but most people use CVS as source control mechanism.


Class Specifications
public invariant getTestedRevision().equals(getTestedClassRevision());

Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
JutilTest(java.lang.String name, java.lang.Class testedClass, Revision testedRevision)
          Initialize a new JutilTest with the given name, tested class and tested revision.
JutilTest(java.lang.String name, Revision testedRevision)
          Initialize a new JutilTest with the given name and tested revision. This is a convenience constructor for Jutil.org test classes.
 
Method Summary
 java.lang.Class getTestedClass()
          Return the class that is tested by this test class.
 Revision getTestedClassRevision()
          Return the field representing the revision of the tested class.
 Revision getTestedRevision()
          Return the revision of the tested class that is tested by this class.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, name, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

JutilTest

public JutilTest(java.lang.String name,
                 Revision testedRevision)

Initialize a new JutilTest with the given name and tested revision.

This is a convenience constructor for Jutil.org test classes. The tested class will be set to the corresponding class in the library. This means, the class with package org.jutil.X when the package of this class is org.jutiltest.X and with the name X when the name of this testclass is TestX.

If you want to set the tested class yourself, use the other constructor.

Parameters:
name - The name of the method that has to be invoked by default.
testedRevision - The revision of the tested class that is tested by this class.

Specifications:
public behavior
requires testedRevision != null;
ensures getTestedClass().getName().equals(new Pattern("org\.jutiltest\").replacer("org.jutil").replace(new Pattern("\.Test[^\.]*").replacer("").replace(getClass().getName())));
ensures getTestedClassRevision().equals(new CVSRevision(getTestedClass().getField("CVS_REVISION").get(null).toString()));
ensures getTestedRevision() == testedRevision;
signals (AssertionFailedError) ( \forall Field f; new Vector(Arrays.asList(getTestedClass().getFields())).contains(f); !f.getName().equals("CVS_REVISION"));
signals (AssertionFailedError) (* There is no class with the name new Pattern("org\\.jutiltest\\").replacer("org.jutil").replace( new Pattern("\\.Test[^\\.]*").replacer("").replace( getClass().getName() ) ) *);
signals (RevisionError) !getTestedRevision().equals(getTestedClassRevision());

JutilTest

public JutilTest(java.lang.String name,
                 java.lang.Class testedClass,
                 Revision testedRevision)
Initialize a new JutilTest with the given name, tested class and tested revision.

Parameters:
name - The name of the method that has to be invoked by default.
testedClass - The class that is tested by this testclass.
testedRevision - The revision of the tested class that is tested by this class.

Specifications:
public behavior
requires testedRevision != null;
requires testedClass != null;
ensures getTestedClass() == testedClass;
ensures getTestedClassRevision().equals(new CVSRevision(getTestedClass().getField("CVS_REVISION").get(null).toString()));
ensures getTestedRevision() == testedRevision;
signals (AssertionFailedError) ( \forall Field f; new Vector(Arrays.asList(getTestedClass().getFields())).contains(f); !f.getName().equals("CVS_REVISION"));
signals (RevisionError) !getTestedRevision().equals(getTestedClassRevision());
Method Detail

getTestedRevision

public Revision getTestedRevision()
Return the revision of the tested class that is tested by this class. This is not necessarily the same revision as the revision of the tested class.

Specifications:
public behavior
ensures \result != null;

getTestedClassRevision

public Revision getTestedClassRevision()
Return the field representing the revision of the tested class.

Specifications:
public behavior
ensures \result != null;

getTestedClass

public java.lang.Class getTestedClass()
Return the class that is tested by this test class.

Specifications:
public behavior
ensures \result != null;