ComponentManager { @SuppressWarnings("unchecked") public <T extends Component> ComponentType<T> getType(Class<T> type) { ComponentType<T> typeInfo = (ComponentType<T>) componentTypes.get(type); if (typeInfo == null) { typeInfo = componentTypeFactory.createComponentType(type); componentTypes.put(type, typeInfo); } return typeInfo; } ComponentManager();  ComponentManager(ComponentTypeFactory componentTypeFactory); T create(Class<T> type); T copy(T instance); @SuppressWarnings("unchecked") ComponentType<T> getType(Class<T> type); @SuppressWarnings("unchecked") ComponentType<T> getType(T instance); void clearCache();  }
@Test public void propertyUsesHighestCommonDenominator() { ComponentType<MismatchedPropertiesComponent> type = componentManager.getType(MismatchedPropertiesComponent.class); Optional<PropertyAccessor<MismatchedPropertiesComponent, ?>> stringProperty = type.getPropertyInfo().getProperty("stringProperty"); assertTrue(stringProperty.isPresent()); assertEquals(CharSequence.class, stringProperty.get().getPropertyType()); }
@Test public void accessProperty() { BasicComponent component = new BasicComponent(); ComponentType<BasicComponent> typeInfo = componentManager.getType(BasicComponent.class); PropertyAccessor<BasicComponent, String> property = (PropertyAccessor<BasicComponent, String>) typeInfo.getPropertyInfo().getProperty("name").get(); property.set(component, "Blue"); assertEquals("Blue", property.get(component)); }
@Test public void accessPublicField() { PublicAttributeComponent component = new PublicAttributeComponent(); ComponentType<PublicAttributeComponent> typeInfo = componentManager.getType(PublicAttributeComponent.class); PropertyAccessor<PublicAttributeComponent, String> property = (PropertyAccessor<PublicAttributeComponent, String>) typeInfo.getPropertyInfo().getProperty("name").get(); property.set(component, "Blue"); assertEquals("Blue", property.get(component)); }