### Question:
UiCreator { public static <C, W extends ComponentWrapper> Stream<W> createUiElements(Object pmo, BindingContext bindingContext, Function<C, W> componentWrapperCreator) { return ComponentAnnotationReader.getComponentDefinitionMethods(pmo.getClass()) .map(m -> createUiElement(m, pmo, bindingContext, componentWrapperCreator)); } private  UiCreator(); static Stream<W> createUiElements(Object pmo,
            BindingContext bindingContext,
            Function<C, W> componentWrapperCreator); static W createUiElement(AnnotatedElement annotatedElement,
            Object pmo,
            BindingContext bindingContext,
            Function<C, W> componentWrapperCreator); static ComponentWrapper createComponent(Object pmo,
            BindingContext bindingContext); @Deprecated @SuppressWarnings("overloads") static ComponentWrapper createComponent(Object pmo,
            BindingContext bindingContext,
            Function<Class<?>, Optional<LinkkiComponentDefinition>> componentDefinitionFinder,
            Function<Class<?>, Optional<LinkkiLayoutDefinition>> layoutDefinitionFinder); @SuppressWarnings("overloads") static ComponentWrapper createComponent(Object pmo,
            BindingContext bindingContext,
            LinkkiComponentDefinition componentDefinition,
            Optional<LinkkiLayoutDefinition> layoutDefinition);  }### Answer:
@Test public void testCreateUiElements() { TestSectionPmo testSectionPmo = new TestSectionPmo(); BindingContext bindingContext = new BindingContext(); List<TestComponentWrapper> wrappers = UiCreator .createUiElements(testSectionPmo, bindingContext, TestComponentWrapper::new) .collect(Collectors.toList()); assertThat(wrappers, hasSize(2)); List<String> componentIds = wrappers.stream().map(TestComponentWrapper::getComponent) .map(TestUiComponent::getId).collect(Collectors.toList()); assertThat(componentIds, contains(TestPmo.PROPERTY_VALUE, TestModelObject.PROPERTY_MODEL_PROP)); List<String> boundIds = bindingContext.getBindings().stream().map(Binding::getBoundComponent) .map(TestUiComponent.class::cast).map(TestUiComponent::getId).collect(Collectors.toList()); assertThat(boundIds, containsInAnyOrder(TestPmo.PROPERTY_VALUE, TestModelObject.PROPERTY_MODEL_PROP)); }
@DisplayName("Given a dynamic field annotated with both @TestUIField and @TestUIField2,") @ParameterizedTest(name = "when the get~ComponentType method returns {0}") @ValueSource(classes = { TestUIField.class, TestUIField2.class }) public void testCreateUiElements_DynamicField(Class<?> componentType) { class DynamicFieldTestPmo { @SuppressFBWarnings("UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS") @TestUIField(position = 10) @TestUIField2(position = 10) public String getDynamic() { return "dyn"; } @SuppressFBWarnings("UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS") public Class<?> getDynamicComponentType() { return componentType; } } DynamicFieldTestPmo testPmo = new DynamicFieldTestPmo(); BindingContext bindingContext = new BindingContext(); List<TestUiComponent> components = UiCreator .createUiElements(testPmo, bindingContext, TestComponentWrapper::new) .map(TestComponentWrapper::getComponent) .collect(Collectors.toList()); assertThat(components, hasSize(1)); if (componentType.equals(TestUIField.class)) { assertThat(components.get(0), is(not(instanceOf(TestUIField2.TestUiComponent2.class)))); } else if (componentType.equals(TestUIField2.class)) { assertThat(components.get(0), is(instanceOf(TestUIField2.TestUiComponent2.class))); } }