@Test public void testCreateComponentValueSetter_UsesCustomConverter() { Label label = new Label(); Consumer<Object> valueSetter = new LabelValueAspectDefinition() .createComponentValueSetter(new LabelComponentWrapper(label)); LinkkiConverterRegistry converterRegistry = LinkkiConverterRegistry.DEFAULT .with(new Converter<String, FooBar>() { private static final long serialVersionUID = 1L; @Override public Result<FooBar> convertToModel(String value, ValueContext context) { return Result.ok(FooBar.valueOf(value)); } @Override public String convertToPresentation(FooBar value, ValueContext context) { return value == FooBar.FOO ? "Foo" : "Bar"; } }); VaadinSession vaadinSession = mock(VaadinSession.class); when(vaadinSession.getAttribute(LinkkiConverterRegistry.class)).thenReturn(converterRegistry); VaadinSession.setCurrent(vaadinSession); valueSetter.accept(FooBar.FOO); assertThat(label.getValue(), is("Foo")); }
@Override public Consumer<Object> createComponentValueSetter(ComponentWrapper componentWrapper) { return v -> ((Label)componentWrapper.getComponent()) .setValue(LabelValueAspectDefinition.toString(v)); }
LabelValueAspectDefinition extends ModelToUiAspectDefinition<Object> { @Override public Consumer<Object> createComponentValueSetter(ComponentWrapper componentWrapper) { return v -> ((Label)componentWrapper.getComponent()) .setValue(LabelValueAspectDefinition.toString(v)); } }
LabelValueAspectDefinition extends ModelToUiAspectDefinition<Object> { @Override public Consumer<Object> createComponentValueSetter(ComponentWrapper componentWrapper) { return v -> ((Label)componentWrapper.getComponent()) .setValue(LabelValueAspectDefinition.toString(v)); }  }
LabelValueAspectDefinition extends ModelToUiAspectDefinition<Object> { @Override public Consumer<Object> createComponentValueSetter(ComponentWrapper componentWrapper) { return v -> ((Label)componentWrapper.getComponent()) .setValue(LabelValueAspectDefinition.toString(v)); }  @Override Aspect<Object> createAspect(); @Override Consumer<Object> createComponentValueSetter(ComponentWrapper componentWrapper); }
LabelValueAspectDefinition extends ModelToUiAspectDefinition<Object> { @Override public Consumer<Object> createComponentValueSetter(ComponentWrapper componentWrapper) { return v -> ((Label)componentWrapper.getComponent()) .setValue(LabelValueAspectDefinition.toString(v)); }  @Override Aspect<Object> createAspect(); @Override Consumer<Object> createComponentValueSetter(ComponentWrapper componentWrapper); static final String NAME; }