@SuppressWarnings("unchecked") @Test public void testRefresh() { BiConsumer<HasItems<?>, ListDataProvider<Object>> dataProviderSetter = mock(BiConsumer.class); AvailableValuesAspectDefinition<HasItems<?>> availableValuesAspectDefinition = new AvailableValuesAspectDefinition<>( AvailableValuesType.DYNAMIC, dataProviderSetter); PropertyDispatcher propertyDispatcher = mock(PropertyDispatcher.class); when(propertyDispatcher.pull(any(Aspect.class))).thenReturn(Arrays.asList(TestEnum.ONE, TestEnum.THREE)); ComboBox<Object> component = mock(ComboBox.class); when(component.getValue()).thenReturn(TestEnum.ONE); Handler uiUpdater = availableValuesAspectDefinition.createUiUpdater(propertyDispatcher, new LabelComponentWrapper(component)); ArgumentCaptor<ListDataProvider<?>> dataProviderCaptor = ArgumentCaptor.forClass(ListDataProvider.class); verify(dataProviderSetter).accept(eq(component), (ListDataProvider<Object>)dataProviderCaptor.capture()); @NonNull ListDataProvider<Object> dataProvider = (ListDataProvider<Object>)dataProviderCaptor.getValue(); Mockito.reset(dataProviderSetter); uiUpdater.apply(); verify(dataProviderSetter).accept(eq(component), (ListDataProvider<Object>)dataProviderCaptor.capture()); ListDataProvider<Object> newDataProvider = (ListDataProvider<Object>)dataProviderCaptor.getValue(); assertThat(newDataProvider, is(not(dataProvider))); }
@Override public Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper) { Aspect<Collection<?>> aspect = createAspect(propertyDispatcher.getProperty(), propertyDispatcher.getValueClass()); List<Object> items = new ArrayList<>(); ListDataProvider<Object> listDataProvider = new ListDataProvider<>(items); setDataProvider(componentWrapper, listDataProvider); return () -> updateItems(items, propertyDispatcher.pull(aspect), componentWrapper); }
AvailableValuesAspectDefinition implements LinkkiAspectDefinition { @Override public Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper) { Aspect<Collection<?>> aspect = createAspect(propertyDispatcher.getProperty(), propertyDispatcher.getValueClass()); List<Object> items = new ArrayList<>(); ListDataProvider<Object> listDataProvider = new ListDataProvider<>(items); setDataProvider(componentWrapper, listDataProvider); return () -> updateItems(items, propertyDispatcher.pull(aspect), componentWrapper); } }
AvailableValuesAspectDefinition implements LinkkiAspectDefinition { @Override public Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper) { Aspect<Collection<?>> aspect = createAspect(propertyDispatcher.getProperty(), propertyDispatcher.getValueClass()); List<Object> items = new ArrayList<>(); ListDataProvider<Object> listDataProvider = new ListDataProvider<>(items); setDataProvider(componentWrapper, listDataProvider); return () -> updateItems(items, propertyDispatcher.pull(aspect), componentWrapper); } AvailableValuesAspectDefinition(AvailableValuesType availableValuesType,
            BiConsumer<C, ListDataProvider<Object>> dataProviderSetter); }
AvailableValuesAspectDefinition implements LinkkiAspectDefinition { @Override public Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper) { Aspect<Collection<?>> aspect = createAspect(propertyDispatcher.getProperty(), propertyDispatcher.getValueClass()); List<Object> items = new ArrayList<>(); ListDataProvider<Object> listDataProvider = new ListDataProvider<>(items); setDataProvider(componentWrapper, listDataProvider); return () -> updateItems(items, propertyDispatcher.pull(aspect), componentWrapper); } AvailableValuesAspectDefinition(AvailableValuesType availableValuesType,
            BiConsumer<C, ListDataProvider<Object>> dataProviderSetter); @Override Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper); Aspect<Collection<?>> createAspect(String propertyName, Class<?> valueClass); }
AvailableValuesAspectDefinition implements LinkkiAspectDefinition { @Override public Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper) { Aspect<Collection<?>> aspect = createAspect(propertyDispatcher.getProperty(), propertyDispatcher.getValueClass()); List<Object> items = new ArrayList<>(); ListDataProvider<Object> listDataProvider = new ListDataProvider<>(items); setDataProvider(componentWrapper, listDataProvider); return () -> updateItems(items, propertyDispatcher.pull(aspect), componentWrapper); } AvailableValuesAspectDefinition(AvailableValuesType availableValuesType,
            BiConsumer<C, ListDataProvider<Object>> dataProviderSetter); @Override Handler createUiUpdater(PropertyDispatcher propertyDispatcher, ComponentWrapper componentWrapper); Aspect<Collection<?>> createAspect(String propertyName, Class<?> valueClass); static final String NAME; }