FileDocCategorySizeDatePackage
TestMutableObject.javaAPI DocExample2935Sun Dec 14 22:47:40 GMT 2003oreilly.hcj.reflection

TestMutableObject

public class TestMutableObject extends TestCase
A reflexive test case to test MutableObject descendants.
author
Robert (Kraythe) Simmons jr.

Fields Summary
private Class
type
The type to be tested.
Constructors Summary
protected TestMutableObject(Class type, String testName)
Creates a new test on a MutableObject.

param
type The type to test.
param
testName The name of the text to run.


	                       	 
	       
		super(testName);
		assert (type != null);
		assert (MutableObject.class.isAssignableFrom(type));
		this.type = type;
	
Methods Summary
public static junit.framework.Testsuite(java.lang.Class type)
Gets the suite of tests for the given class.

param
type The MutableObject type to test.
return
The test suite.
throws
NullPointerException if null is passed for the type.
throws
IllegalArgumentException If a type is passed that is not a MutableObject descendant.

		if (type == null) {
			throw new NullPointerException("type");  //$NON-NLS-1$
		}
		if (!MutableObject.class.isAssignableFrom(type)) {
			throw new IllegalArgumentException("type");  //$NON-NLS-1$
		}

		TestSuite suite = new TestSuite(type.getName());
		suite.addTest(new TestMutableObject(type, "testConstraintsExist"));
		return suite;
	
public voidtestConstraintsExist()
Tests that constraints exist for each of the properties in the data model.

throws
RuntimeException If there is a an EntrospectionException.

		try {
			final PropertyDescriptor[] props =
				Introspector.getBeanInfo(type, Object.class)
				            .getPropertyDescriptors();

			for (int idx = 0; idx < props.length; idx++) {
				ObjectConstraint constraint =
					MutableObject.getConstraint(type, props[idx].getName());
				assertNotNull("Property " + props[idx].getName()
				              + " does not have a constraint.", constraint);
			}
		} catch (final IntrospectionException ex) {
			throw new RuntimeException();
		}