@SuppressWarnings("unchecked")
@Test
public void field_read_and_write() throws Exception
{
ApplicationStateManager manager = newApplicationStateManager();
Logger logger = mockLogger();
MutableComponentModel model = mockMutableComponentModel();
InternalComponentResources resources = mockInternalComponentResources();
String componentClassName = StateHolder.class.getName();
Class asoClass = ReadOnlyBean.class;
ClassPool pool = new ClassPool();
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
pool.appendClassPath(new LoaderClassPath(contextLoader));
Loader loader = new Loader(contextLoader, pool);
loader.delegateLoadingOf("org.apache.tapestry.");
CtClass ctClass = pool.get(componentClassName);
InternalClassTransformation transformation = new InternalClassTransformationImpl(ctClass,
_contextClassLoader, logger, null);
replay();
new ApplicationStateWorker(manager).transform(transformation, model);
verify();
transformation.finish();
Class transformedClass = pool.toClass(ctClass, loader);
Instantiator instantiator = transformation.createInstantiator(transformedClass);
Object component = instantiator.newInstance(resources);
// Test the companion flag field
expect(manager.exists(asoClass)).andReturn(true);
replay();
assertEquals(_access.get(component, "beanExists"), true);
verify();
// Test read property (get from ASM)
Object aso = new ReadOnlyBean();
train_get(manager, asoClass, aso);
replay();
assertSame(_access.get(component, "bean"), aso);
verify();
// Test write property (set ASM)
Object aso2 = new ReadOnlyBean();
manager.set(asoClass, aso2);
replay();
_access.set(component, "bean", aso2);