### Question:
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; }### Answer:
@Test public void testCreateComponentValueSetter_SetsString() { Label label = new Label(); Consumer<Object> valueSetter = new LabelValueAspectDefinition() .createComponentValueSetter(new LabelComponentWrapper(label)); valueSetter.accept("foo"); assertThat(label.getValue(), is("foo")); }
@Test public void testCreateComponentValueSetter_UsesToString() { Label label = new Label(); Consumer<Object> valueSetter = new LabelValueAspectDefinition() .createComponentValueSetter(new LabelComponentWrapper(label)); valueSetter.accept(new Object() { @Override public String toString() { return "bar"; } }); assertThat(label.getValue(), is("bar")); }
@Test public void testCreateComponentValueSetter_UsesStandardConverter() { Label label = new Label(); Consumer<Object> valueSetter = new LabelValueAspectDefinition() .createComponentValueSetter(new LabelComponentWrapper(label)); valueSetter.accept(Integer.valueOf(123456)); assertThat(label.getValue(), is("123.456")); }
@Test public void testCreateComponentValueSetter_UsesStandardConverter_DependingOnUiLocale() { Label label = new Label(); Consumer<Object> valueSetter = new LabelValueAspectDefinition() .createComponentValueSetter(new LabelComponentWrapper(label)); UI ui = MockUi.mockUi(); when(ui.getLocale()).thenReturn(Locale.US); valueSetter.accept(Integer.valueOf(123456)); assertThat(label.getValue(), is("123,456")); }
@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")); }