@SuppressWarnings("unchecked")
@Test
public void field_read_and_write() throws Exception
{
ApplicationStateManager manager = mockApplicationStateManager();
Logger logger = mockLogger();
MutableComponentModel model = mockMutableComponentModel();
InternalComponentResources resources = mockInternalComponentResources();
ComponentClassCache cache = mockComponentClassCache();
train_getLogger(model, logger);
Class asoClass = SimpleASO.class;
CtClass ctClass = findCtClass(StateHolder.class);
train_forName(cache, asoClass);
replay();
InternalClassTransformation transformation = new InternalClassTransformationImpl(classFactory, ctClass, null,
model, null);
new ApplicationStateWorker(manager, cache).transform(transformation, model);
verify();
transformation.finish();
Instantiator instantiator = transformation.createInstantiator();
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 SimpleASO();
train_get(manager, asoClass, aso);
replay();
assertSame(access.get(component, "bean"), aso);
verify();
// Test write property (set ASM)
Object aso2 = new SimpleASO();
manager.set(asoClass, aso2);
replay();
access.set(component, "bean", aso2);