package com.vaadin.data.validator; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; import com.vaadin.data.ValidationResult; import com.vaadin.data.ValueContext; /** * @author Vaadin Ltd * */ public class NotEmptyValidatorTest { @Test public void nullValueIsDisallowed() { NotEmptyValidator validator = new NotEmptyValidator<>("foo"); ValidationResult result = validator.apply(null, new ValueContext()); assertTrue(result.isError()); assertEquals("foo", result.getErrorMessage()); } @Test public void emptyValueIsDisallowed() { NotEmptyValidator validator = new NotEmptyValidator<>("foo"); ValidationResult result = validator.apply("", new ValueContext()); assertTrue(result.isError()); assertEquals("foo", result.getErrorMessage()); } @Test public void nonNullValueIsAllowed() { NotEmptyValidator validator = new NotEmptyValidator<>("foo"); Object value = new Object(); ValidationResult result = validator.apply(value, new ValueContext()); assertFalse(result.isError()); assertFalse(result.isError()); } }