use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.
the class BindLabelValueAspectDefinitionTest method testCreateComponentValueSetter_UsesCustomConverter.
@Test
void testCreateComponentValueSetter_UsesCustomConverter() {
LinkkiText label = new LinkkiText();
Consumer<Object> valueSetter = new BindLabelValueAspectDefinition().createComponentValueSetter(new NoLabelComponentWrapper(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.getText(), is("Foo"));
}
use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.
the class FormattedDoubleToStringConverterTest method testConvertToModel_Null.
@Test
public void testConvertToModel_Null() {
FormattedDoubleToStringConverter converter = new FormattedDoubleToStringConverter("0.00");
ValueContext context = new ValueContext(Locale.GERMAN);
assertThat(converter.convertToModel("", context).getOrThrow(s -> new AssertionError(s)), is(nullValue()));
}
use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.
the class FormattedDoubleToStringConverterTest method testConvertToPresentation.
@Test
public void testConvertToPresentation() {
FormattedDoubleToStringConverter converter = new FormattedDoubleToStringConverter("0.00");
ValueContext context = new ValueContext(Locale.GERMAN);
assertThat(converter.convertToPresentation(0.2, context), is("0,20"));
}
use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.
the class FormattedDoubleToStringConverterTest method testConvertToModel.
@Test
public void testConvertToModel() {
FormattedDoubleToStringConverter converter = new FormattedDoubleToStringConverter("0.00");
ValueContext context = new ValueContext(Locale.GERMAN);
assertThat(converter.convertToModel("1,23", context).getOrThrow(s -> new AssertionError(s)), is(1.23));
}
use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.
the class FormattedIntegerToStringConverterTest method testConvertToModel_Null.
@Test
public void testConvertToModel_Null() {
FormattedIntegerToStringConverter converter = new FormattedIntegerToStringConverter("#,##0");
ValueContext context = new ValueContext(Locale.GERMAN);
assertThat(converter.convertToModel("", context).getOrThrow(s -> new AssertionError(s)), is(nullValue()));
}
Aggregations