Search in sources :

Example 26 with ValueContext

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

the class LocalDateTimeToStringConverterTest method testConvertToPresentation.

@Test
void testConvertToPresentation() {
    LocalDateTimeToStringConverter converter = new LocalDateTimeToStringConverter();
    LocalDateTime dateToConvert = LocalDateTime.of(1234, 5, 6, 7, 8, 9);
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.GERMANY))).isEqualTo("06.05.1234 07:08");
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.GERMAN))).isEqualTo("06.05.1234 07:08");
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.ENGLISH))).isEqualTo("05/06/1234 7:08 AM");
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.UK))).isEqualTo("06/05/1234 07:08");
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.US))).isEqualTo("05/06/1234 7:08 AM");
}
Also used : LocalDateTime(java.time.LocalDateTime) ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Example 27 with ValueContext

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

the class LocalDateToStringConverterTest method testConvertToModel_Null.

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

Example 28 with ValueContext

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

the class LocalDateToStringConverterTest method testConvertToModel_IncompatibleLocale.

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

Example 29 with ValueContext

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

the class LocalDateToStringConverterTest method testConvertToModel.

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

Example 30 with ValueContext

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

the class LocalDateToStringConverterTest method testConvertToPresentation.

@Test
void testConvertToPresentation() {
    LocalDateToStringConverter converter = new LocalDateToStringConverter();
    LocalDate dateToConvert = LocalDate.of(1234, 5, 6);
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.GERMANY))).isEqualTo("06.05.1234");
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.GERMAN))).isEqualTo("06.05.1234");
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.ENGLISH))).isEqualTo("05/06/1234");
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.UK))).isEqualTo("06/05/1234");
    Assertions.assertThat(converter.convertToPresentation(dateToConvert, new ValueContext(Locale.US))).isEqualTo("05/06/1234");
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) LocalDate(java.time.LocalDate) 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