Binder { public Map<String, Component> getAlreadyAssignedFields(Object controller) { if (controller == null) { return Collections.emptyMap(); } Map<String, Component> assignedFields = new HashMap<String, Component>(); for (Field field : ReflectionUtils.getAllDeclaredFieldsAnnotatedWith( controller.getClass(), UiField.class)) { try { field.setAccessible(true); Object value = field.get(controller); if (value instanceof Component) { assignedFields.put(extractComponentId(field), (Component) value); } } catch (IllegalAccessException e) { getLogger().log(Level.WARNING, "Exception while accessing controller object fields.", e); } } return assignedFields; } Binder();  Binder(String idPrefix); void bind(Component componentRoot, Object controller); Map<String, Component> getAlreadyAssignedFields(Object controller);  }
@Test public void getAlreadyAssignedFields_yieldFieldFromClass() { ControllerWithFieldBinding controller = new ControllerWithFieldBinding( new Button("myButton")); Binder binder = new Binder(); Map<String, Component> assignedFields = binder .getAlreadyAssignedFields(controller); assertEquals(1, assignedFields.size()); }
@Test public void getAlreadyAssignedFields_yieldFieldFromBaseClass() { SubcontrollerWithoutFieldBinding controller = new SubcontrollerWithoutFieldBinding( new Button("myButton")); Binder binder = new Binder(); Map<String, Component> assignedFields = binder .getAlreadyAssignedFields(controller); assertEquals(1, assignedFields.size()); }