Commit 2050ea80 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

proper exception is thrown when color is invalid

parent dcfc788d
......@@ -229,7 +229,11 @@ public class ColorSchemaReader {
}
}
if (colorColumn != null) {
schema.setColor(colorParser.parse(values[colorColumn]));
try {
schema.setColor(colorParser.parse(values[colorColumn]));
} catch (InvalidArgumentException e) {
throw new InvalidColorSchemaException(errorPrefix + e.getMessage(), e);
}
}
if (identifierColumn != null && !values[identifierColumn].equals("")) {
processGeneralIdentifier(values[identifierColumn], schema, errorPrefix);
......@@ -535,7 +539,11 @@ public class ColorSchemaReader {
schema.setValue(parseValueColumn(values[valueColumn], errorPrefix));
}
if (colorColumn != null && !values[colorColumn].isEmpty()) {
schema.setColor(colorParser.parse(values[colorColumn]));
try {
schema.setColor(colorParser.parse(values[colorColumn]));
} catch (InvalidArgumentException e) {
throw new InvalidColorSchemaException(errorPrefix + e.getMessage(), e);
}
}
if (schema.getValue() != null && schema.getColor() != null) {
throw new InvalidColorSchemaException(errorPrefix + "Either color or value can be defined but found both");
......
......@@ -378,6 +378,23 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
}
}
@Test
public void testColoringWithEmptyColor() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
String input = "name\tcolor\ns1\tx";
reader.readColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), params);
fail("Exception expected");
} catch (InvalidColorSchemaException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testColoringWithInvalidValueAndColor2() throws Exception {
try {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment