Skip to content
Snippets Groups Projects
Commit dcfc788d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when empty or null color is provided throw proper exception

parent 67b8c7ef
No related branches found
No related tags found
2 merge requests!805Merge 13.1.0 beta.1,!798Resolve "MINERVANET - Error Report 72"
......@@ -47,6 +47,10 @@ public class ColorParser {
* @return {@link Color} obtained from input text
*/
public Color parse(String string) {
if (string==null || string.isEmpty()) {
throw new InvalidArgumentException(
"Invalid color value: " + string + ". Correct format: #xxxxxx (where x is a hex value)");
}
if (string.charAt(0) != '#') {
string = "#" + string;
}
......
......@@ -64,6 +64,18 @@ public class ColorParserTest {
}
}
@Test(expected=InvalidArgumentException.class)
public void testParseNull() throws Exception {
ColorParser parser = new ColorParser();
parser.parse(null);
}
@Test(expected=InvalidArgumentException.class)
public void testParseEmpty() throws Exception {
ColorParser parser = new ColorParser();
parser.parse("");
}
@Test
public void testSetColorToHtmlString() throws Exception {
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment