add support for i18n validation messages

This commit is contained in:
Andreas Billmann
2015-12-17 20:44:07 +01:00
parent 5d53fff577
commit 9278bfa13a
9 changed files with 155 additions and 71 deletions

View File

@@ -10,6 +10,7 @@ import java.util.Collection;
import static java.util.Arrays.asList;
import static ninja.javafx.smartcsv.validation.ConfigMock.columnSectionConfig;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -73,7 +74,7 @@ public class ValidatorTest {
// assertion
assertThat(result == null, is(expectedResult));
if (!expectedResult) {
assertThat(result.getMessage(), is(expectedError));
assertThat(result.getMessages(), contains(expectedError));
}
}
@@ -84,22 +85,22 @@ public class ValidatorTest {
public static Collection validationConfigurations() {
return asList(new Object[][] {
{ "column", "not empty", true, "column", "value", true, null },
{ "column", "not empty", true, "column", "", false, "should not be empty\n" },
{ "column", "not empty", true, "column", null, false, "should not be empty\n" },
{ "column", "not empty", true, "column", "", false, "should not be empty" },
{ "column", "not empty", true, "column", null, false, "should not be empty" },
{ "column", "integer", true, "column", "999", true, null },
{ "column", "integer", true, "column", "a", false, "should be an integer\n" },
{ "column", "integer", true, "column", "a", false, "should be an integer" },
{ "column", "minlength", 2, "column", "12", true, null },
{ "column", "minlength", 2, "column", "1", false, "has not min length of 2\n" },
{ "column", "minlength", 2, "column", "1", false, "has not min length of 2" },
{ "column", "maxlength", 2, "column", "12", true, null },
{ "column", "maxlength", 2, "column", "123", false, "has not max length of 2\n" },
{ "column", "maxlength", 2, "column", "123", false, "has not max length of 2" },
{ "column", "date", "yyyyMMdd", "column", "20151127", true, null },
{ "column", "date", "yyyyMMdd", "column", "27.11.2015", false, "is not a date of format yyyyMMdd\n" },
{ "column", "date", "yyyyMMdd", "column", "27.11.2015", false, "is not a date of format yyyyMMdd" },
{ "column", "alphanumeric", true, "column", "abcABC123", true, null },
{ "column", "alphanumeric", true, "column", "-abcABC123", false, "should not be alphanumeric\n" },
{ "column", "alphanumeric", true, "column", "-abcABC123", false, "should not be alphanumeric" },
{ "column", "regexp", "[a-z]*", "column", "abc", true, null },
{ "column", "regexp", "[a-z]*", "column", "abcA", false, "does not match [a-z]*\n" },
{ "column", "regexp", "[a-z]*", "column", "abcA", false, "does not match [a-z]*" },
{ "column", "groovy", "value.contains('a')? 'true' : 'no a inside'", "column", "abcdef", true, null },
{ "column", "groovy", "value.contains('a')? 'true' : 'no a inside'", "column", "bcdefg", false, "no a inside\n" },
{ "column", "groovy", "value.contains('a')? 'true' : 'no a inside'", "column", "bcdefg", false, "no a inside" },
});
}