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");
}
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();
}
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();
}
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));
}
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");
}
Aggregations