package com.ericfeminella.tests
{
import com.ericfeminella.collections.Collection;
import com.ericfeminella.collections.Iterator;
import flexunit.framework.TestCase;
/**
*
* <code>TestSuiteFactoryClient</code> provides a convenience class which
* determines if item in an <code>Array</code> is of type <code>TestCase</code>
*
* @example The following example demonstrates how a typical implementation
* of <code>TestSuiteFactoryClient</code>, whereas a Class, "AllTests" extends
* <code>TestSuiteFactoryClient</code> in order to provide a collection of
* <code>TestCase</code> objects to <code>TestSuiteFactory.createSuites</code>
*
* <listing version="3.0">
*
* public class AllTests extends TestSuiteFactoryClient
* {
* private static const ALL_TESTS:Array = [ TestA,
* TestB,
* TestC
* ];
* public function AllTests()
* {
* super( ALL_TESTS );
* }
* }
*
* </listing>
*
*/
public class TestSuiteFactoryClient
{
/**
*
* Defines the collection of <code>TestCase</code> objects in which
* to pass to <code>TestSuiteFactory.createSuites</code>
*
*/
protected var source:Collection;
/**
*
* <code>TestSuiteFactoryClient</code> constructor creates a new collection
* which references the <code>Array</code> of <code>TestCase</code> objects
*
* @param <code>Array</code> of <code>TestCase</code> objects
*
*/
public function TestSuiteFactoryClient(testsArray:Array)
{
source = new Collection( testsArray );
validateTests();
}
/**
*
* Returns a <code>Collection</code> of <code>TestCase</code> objects
*
* @return <code>Collection</code>
*
*/
public function get allTests() : Collection
{
return source;
}
/**
*
* Validates that each item specified in the <code>Array</code> passed to the
* constructor is of type, <code>TestCase</code>. If an item specified in the
* <code>Array</code> is not of type <code>TestCase</code>, an exception is
* thrown.
*
* throws <code>Exception</code>
*
*/
protected function validateTests() : void
{
var it:Iterator = source.iterator;
var testCase:TestCase;
var TestClass:Class;
while ( it.hasNext() )
{
try {
TestClass = it.next() as Class;
testCase = new TestClass();
}
catch (error:Error )
{
throw new Error( "item must be of type TestCase" );
}
}
it.reset();
}
}
}