Search in sources :

Example 11 with ValueContext

use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.

the class FormattedIntegerToStringConverterTest method testConvertToPresentation.

@Test
public void testConvertToPresentation() {
    FormattedIntegerToStringConverter converter = new FormattedIntegerToStringConverter("#,##0");
    ValueContext context = new ValueContext(Locale.GERMAN);
    assertThat(converter.convertToPresentation(12345, context), is("12.345"));
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Example 12 with ValueContext

use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.

the class FormattedDecimalFieldToStringConverterTest method testConvertToModel.

@ParameterizedTest
@MethodSource("data")
public void testConvertToModel(Decimal decimalValue, String stringValue) {
    ValueContext context = new ValueContext(Locale.GERMAN);
    assertThat(converter.convertToModel(stringValue, context).getOrThrow(s -> new AssertionError(s)), is(decimalValue));
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Test(org.junit.jupiter.api.Test) Decimal(org.faktorips.values.Decimal) Arrays(java.util.Arrays) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Locale(java.util.Locale) Collection(java.util.Collection) ValueContext(com.vaadin.flow.data.binder.ValueContext) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with ValueContext

use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.

the class LocalDateTimeToStringConverterTest method testConvertToModel_Null.

@Test
void testConvertToModel_Null() throws Exception {
    LocalDateTimeToStringConverter converter = new LocalDateTimeToStringConverter();
    Result<LocalDateTime> result = converter.convertToModel(null, new ValueContext(Locale.US));
    Assertions.assertThat(result.isError()).isFalse();
    Assertions.assertThat(result.getOrThrow(m -> new Exception(m))).isNull();
}
Also used : LocalDateTime(java.time.LocalDateTime) ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Example 14 with ValueContext

use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.

the class LocalDateTimeToStringConverterTest method testConvertToModel.

@Test
void testConvertToModel() throws Exception {
    LocalDateTimeToStringConverter converter = new LocalDateTimeToStringConverter();
    Result<LocalDateTime> result = converter.convertToModel("01.02.3456 07:08", new ValueContext(Locale.GERMANY));
    Assertions.assertThat(result.isError()).isFalse();
    Assertions.assertThat(result.getOrThrow(m -> new Exception(m))).isEqualTo(LocalDateTime.of(3456, 2, 1, 7, 8));
}
Also used : LocalDateTime(java.time.LocalDateTime) ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Example 15 with ValueContext

use of com.vaadin.flow.data.binder.ValueContext in project linkki by linkki-framework.

the class LocalDateTimeToStringConverterTest method testConvertToModel_IncompatibleLocale.

@Test
void testConvertToModel_IncompatibleLocale() {
    LocalDateTimeToStringConverter converter = new LocalDateTimeToStringConverter();
    Result<LocalDateTime> result = converter.convertToModel("01.02.3456 07:08", new ValueContext(Locale.US));
    Assertions.assertThat(result.isError()).isTrue();
}
Also used : LocalDateTime(java.time.LocalDateTime) ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Aggregations

ValueContext (com.vaadin.flow.data.binder.ValueContext)31 Test (org.junit.jupiter.api.Test)24 Locale (java.util.Locale)6 ValidationResult (com.vaadin.flow.data.binder.ValidationResult)5 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)5 LocalDate (java.time.LocalDate)4 LocalDateTime (java.time.LocalDateTime)4 Matchers.is (org.hamcrest.Matchers.is)4 Matchers.nullValue (org.hamcrest.Matchers.nullValue)4 Test (org.junit.Test)3 Result (com.vaadin.flow.data.binder.Result)2 VaadinSession (com.vaadin.flow.server.VaadinSession)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Key (com.vaadin.flow.component.Key)1 UI (com.vaadin.flow.component.UI)1 Button (com.vaadin.flow.component.button.Button)1 ButtonVariant (com.vaadin.flow.component.button.ButtonVariant)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1