net.sourceforge.groboutils.junit.v1.iftc
Class InterfaceTestSuite

java.lang.Object
  extended byjunit.framework.TestSuite
      extended bynet.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite
All Implemented Interfaces:
junit.framework.Test

public class InterfaceTestSuite
extends junit.framework.TestSuite

Allows for tests to be written on interfaces or abstract classes. These must be run through an InterfaceTestSuite to have the implemented object be set correctly.

This class extends TestSuite only for the purpose of being a testing repository. The act of parsing TestCase classes is delegated to new TestSuite instances. A new instance will be created for each test method (just as TestSuite does), If a TestCase class has a constructor which is of the form ( String, ImplFactory ), then each test method instance will be created once for each known ImplFactory object; these will be stored and executed through the ImplFactory class. All other classes will be added just as TestSuite does (the standard method).

The creation of test instances is delayed until the tests are actually retrieved via the testAt(), tests(), and testCount() methods. Therefore, adding new Classes and ImplFactory instances after the creation time will cause an error, due to problems with addTest() (they cannot be removed).

Currently, this class is slow: it does not do smart things like cache results from inspection on the same class object.

Since:
March 2, 2002
Version:
$Date: 2003/02/10 22:52:20 $
Author:
Matt Albrecht groboclown@users.sourceforge.net
See Also:
InterfaceTestCase, ImplFactory, TestSuite

Constructor Summary
InterfaceTestSuite()
          Constructs a TestSuite from the given class, and sets the initial set of creators.
InterfaceTestSuite(java.lang.Class theClass)
          Constructs a TestSuite from the given class, and sets the initial set of creators.
InterfaceTestSuite(java.lang.Class theClass, ImplFactory f)
          Constructs a TestSuite from the given class, and sets the initial set of creators.
 
Method Summary
 void addFactories(ImplFactory[] f)
          Add an array of new Implementation factories to the suite.
 void addFactory(ImplFactory f)
          Add a new Implementation factory to the suite.
 void addInterfaceTestSuite(InterfaceTestSuite t)
          Add an InterfaceTestSuite to this suite.
 void addTests(junit.framework.Test[] t)
          Add an array of tests to the suite.
 void addTestSuite(java.lang.Class theClass)
          Adds all the methods starting with "test" as test cases to the suite.
protected  ITestCreator createTestCreator(java.util.Vector vf)
          Create a TestCreator that contains the knowledge of how to properly parse and generate tests for all types of supported test classes.
protected  void loadTestSuite(java.lang.Class testClass, TestClassCreator tcc)
          Load all the tests and warnings from the class and the creator type into this instance's suite of tests.
protected  void loadTestSuites()
          Load all the tests from the cache of classes and factories.
 junit.framework.Test testAt(int index)
           
 int testCount()
           
 java.util.Enumeration tests()
           
 
Methods inherited from class junit.framework.TestSuite
addTest, countTestCases, createTest, getName, getTestConstructor, run, runTest, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InterfaceTestSuite

public InterfaceTestSuite()
Constructs a TestSuite from the given class, and sets the initial set of creators. Adds all the methods starting with "test" as test cases to the suite.


InterfaceTestSuite

public InterfaceTestSuite(java.lang.Class theClass)
Constructs a TestSuite from the given class, and sets the initial set of creators. Adds all the methods starting with "test" as test cases to the suite.

Parameters:
theClass - the class under inspection

InterfaceTestSuite

public InterfaceTestSuite(java.lang.Class theClass,
                          ImplFactory f)
Constructs a TestSuite from the given class, and sets the initial set of creators. Adds all the methods starting with "test" as test cases to the suite.

Parameters:
theClass - the class under inspection
f - a factory to add to this suite.
Method Detail

addFactory

public void addFactory(ImplFactory f)
Add a new Implementation factory to the suite. This should only be called before any tests are extracted from this suite. If it is called after, then an IllegalStateException will be generated.

Parameters:
f - a factory to add to this suite.
Throws:
java.lang.IllegalArgumentException - if f is null
java.lang.IllegalStateException - if the tests have already been generated

addFactories

public void addFactories(ImplFactory[] f)
Add an array of new Implementation factories to the suite. This should only be called before any tests are extracted from this suite.

Parameters:
f - a set of factories to add to this suite.
Throws:
java.lang.IllegalArgumentException - if f is null, or any element in the list is null
java.lang.IllegalStateException - if the tests have already been generated

addInterfaceTestSuite

public void addInterfaceTestSuite(InterfaceTestSuite t)
Add an InterfaceTestSuite to this suite. If an interface extends another interface, it should add it's super interface's test suite through this method. The same goes for any abstract or base class. Adding the parent suite through this method will cause both suites to share creators. In fact, the parent suite cannot have any factories when passed into this method, because they will be ignored.

This allows for the flexibility of determining whether to add a full test suite, without sharing factories, or not.

Parameters:
t - a test to add to the suite. It can be null.

addTests

public void addTests(junit.framework.Test[] t)
Add an array of tests to the suite.

Parameters:
t - a set of tests to add to this suite.

addTestSuite

public void addTestSuite(java.lang.Class theClass)
Adds all the methods starting with "test" as test cases to the suite.

Overrides the parent implementation to allow for InterfaceTests.

Parameters:
theClass - the class under inspection
Throws:
java.lang.IllegalArgumentException - if theClass is null
java.lang.IllegalStateException - if the tests have already been generated

testAt

public junit.framework.Test testAt(int index)

testCount

public int testCount()

tests

public java.util.Enumeration tests()

loadTestSuites

protected void loadTestSuites()
Load all the tests from the cache of classes and factories.


loadTestSuite

protected void loadTestSuite(java.lang.Class testClass,
                             TestClassCreator tcc)
Load all the tests and warnings from the class and the creator type into this instance's suite of tests.

Parameters:
testClass - the class being inspected for test instance creation.
tcc - the creator type that will be used to create new tests.

createTestCreator

protected ITestCreator createTestCreator(java.util.Vector vf)
Create a TestCreator that contains the knowledge of how to properly parse and generate tests for all types of supported test classes.

Returns:
the new creator.


Copyright © 2001-2003 by The GroboUtils Project