mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
add support for i18n validation messages
This commit is contained in:
@@ -32,12 +32,15 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static ninja.javafx.smartcsv.validation.ConfigMock.headerSectionConfig;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* unit test for header validator
|
||||
@@ -49,7 +52,7 @@ public class HeaderValidationTest {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private Config config;
|
||||
private Boolean expectedResult;
|
||||
private String expectedError;
|
||||
private List<String> expectedErrors;
|
||||
private String[] headerNames;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -64,11 +67,11 @@ public class HeaderValidationTest {
|
||||
public HeaderValidationTest(String[] configHeaderNames,
|
||||
String[] headerNames,
|
||||
Boolean expectedResult,
|
||||
String expectedError) {
|
||||
List<String> expectedErrors) {
|
||||
this.config = headerSectionConfig(configHeaderNames);
|
||||
this.headerNames = headerNames;
|
||||
this.expectedResult = expectedResult;
|
||||
this.expectedError = expectedError;
|
||||
this.expectedErrors = expectedErrors;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -91,7 +94,7 @@ public class HeaderValidationTest {
|
||||
// assertion
|
||||
assertThat(result == null, is(expectedResult));
|
||||
if (!expectedResult) {
|
||||
assertThat(result.getMessage(), is(expectedError));
|
||||
assertTrue(result.getMessages().containsAll(expectedErrors));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +106,9 @@ public class HeaderValidationTest {
|
||||
return asList(new Object[][] {
|
||||
{ new String[] {}, new String[] {}, true, null },
|
||||
{ new String[] {"a"}, new String[] {"a"}, true, null },
|
||||
{ new String[] {"a"}, new String[] {"b"}, false, "header number 0 does not match \"a\" should be \"b\"\n" },
|
||||
{ new String[] {"a"}, new String[] {"a","b"}, false, "number of headers is not correct! there are 2 but there should be 1\n" },
|
||||
{ new String[] {"a", "b"}, new String[] {"b", "a"}, false, "header number 0 does not match \"a\" should be \"b\"\nheader number 1 does not match \"b\" should be \"a\"\n" }
|
||||
{ new String[] {"a"}, new String[] {"b"}, false, Arrays.asList("header number 0 does not match \"a\" should be \"b\"") },
|
||||
{ new String[] {"a"}, new String[] {"a","b"}, false, Arrays.asList("number of headers is not correct! there are 2 but there should be 1") },
|
||||
{ new String[] {"a", "b"}, new String[] {"b", "a"}, false, Arrays.asList("header number 0 does not match \"a\" should be \"b\"", "header number 1 does not match \"b\" should be \"a\"") }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user