Commit dcfc788d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when empty or null color is provided throw proper exception

parent 67b8c7ef
......@@ -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 {
......
Supports Markdown
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