FileDocCategorySizeDatePackage
ReflectionOptimizerTest.javaAPI DocHibernate 3.2.51841Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.bytecode.javassist

ReflectionOptimizerTest

public class ReflectionOptimizerTest extends org.hibernate.junit.UnitTestCase
author
Steve Ebersole

Fields Summary
Constructors Summary
public ReflectionOptimizerTest(String string)

		super( string );
	
Methods Summary
private voidassertEquivalent(java.lang.Object[] checkValues, java.lang.Object[] values)

		assertEquals( "Different lengths", checkValues.length, values.length );
		for ( int i = 0; i < checkValues.length; i++ ) {
			assertEquals( "different values at index [" + i + "]", checkValues[i], values[i] );
		}
	
public static junit.framework.TestSuitesuite()

		return new TestSuite( ReflectionOptimizerTest.class );
	
public voidtestReflectionOptimization()

		BytecodeProviderImpl provider = new BytecodeProviderImpl();
		ReflectionOptimizer optimizer = provider.getReflectionOptimizer(
				Bean.class,
		        BeanReflectionHelper.getGetterNames(),
		        BeanReflectionHelper.getSetterNames(),
		        BeanReflectionHelper.getTypes()
		);
		assertNotNull( optimizer );
		assertNotNull( optimizer.getInstantiationOptimizer() );
		assertNotNull( optimizer.getAccessOptimizer() );

		Object instance = optimizer.getInstantiationOptimizer().newInstance();
		assertEquals( instance.getClass(), Bean.class );
		Bean bean = ( Bean ) instance;

		optimizer.getAccessOptimizer().setPropertyValues( bean, BeanReflectionHelper.TEST_VALUES );
		assertEquals( bean.getSomeString(), BeanReflectionHelper.TEST_VALUES[0] );
		Object[] values = optimizer.getAccessOptimizer().getPropertyValues( bean );
		assertEquivalent( values, BeanReflectionHelper.TEST_VALUES );