Search in sources :

Example 16 with ValueContext

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

the class LocalDateTimeToStringConverterTest method testConvertToPresentation_Null.

@Test
void testConvertToPresentation_Null() {
    LocalDateTimeToStringConverter converter = new LocalDateTimeToStringConverter();
    String string = converter.convertToPresentation(null, new ValueContext(Locale.GERMANY));
    Assertions.assertThat(string).isNull();
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Example 17 with ValueContext

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

the class LocalDateToStringConverterTest method testConvertToPresentation_Null.

@Test
void testConvertToPresentation_Null() {
    LocalDateToStringConverter converter = new LocalDateToStringConverter();
    String string = converter.convertToPresentation(null, new ValueContext(Locale.GERMANY));
    Assertions.assertThat(string).isNull();
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Example 18 with ValueContext

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

the class NullHandlingConverterWrapperTest method testConvertToModel_NonnullValue.

@Test
public void testConvertToModel_NonnullValue() {
    FormattedIntegerToStringConverter converter = new FormattedIntegerToStringConverter("#,##0");
    NullHandlingConverterWrapper<String, Integer> wrapper = new NullHandlingConverterWrapper<>(converter);
    ValueContext context = new ValueContext(Locale.GERMAN);
    Result<Integer> converterResult = converter.convertToModel("123", context);
    Result<Integer> wrapperResult = wrapper.convertToModel("123", context);
    // converter returns value -> wrapper returns same value
    assertThat(converterResult.isError(), is(false));
    assertThat(getValue(converterResult), is(123));
    assertThat(wrapperResult.isError(), is(false));
    assertThat(getValue(wrapperResult), is(123));
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Example 19 with ValueContext

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

the class NullHandlingConverterWrapperTest method testConvertToModel_NullValue.

@Test
public void testConvertToModel_NullValue() {
    FormattedIntegerToStringConverter converter = new FormattedIntegerToStringConverter("#,##0");
    NullHandlingConverterWrapper<String, Integer> wrapper = new NullHandlingConverterWrapper<>(converter);
    ValueContext context = new ValueContext(Locale.GERMAN);
    Result<Integer> converterResult = converter.convertToModel("", context);
    Result<Integer> wrapperResult = wrapper.convertToModel("", context);
    // converter returns null -> wrapper returns error
    assertThat(converterResult.isError(), is(false));
    assertThat(getValue(converterResult), is(nullValue()));
    assertThat(wrapperResult.isError(), is(true));
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) Test(org.junit.jupiter.api.Test)

Example 20 with ValueContext

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

the class NotEmptyValidatorTest method nullValueIsDisallowed.

@Test
public void nullValueIsDisallowed() {
    NotEmptyValidator<String> validator = new NotEmptyValidator<>("foo");
    ValidationResult result = validator.apply(null, new ValueContext());
    Assert.assertTrue(result.isError());
    Assert.assertEquals("foo", result.getErrorMessage());
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) ValidationResult(com.vaadin.flow.data.binder.ValidationResult) Test(org.junit.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