CssColorConverter implements Converter<Color> { @Override public Color parse(String text) throws ConversionException { try { final String[] rgbValues = text.split(","); final boolean isCommaSeparatedColorValue = rgbValues.length == 3; if (isCommaSeparatedColorValue) { return new Color(Integer.parseInt(rgbValues[0]), Integer.parseInt(rgbValues[1]), Integer.parseInt(rgbValues[2])); } return Color.decode("0x" + (text.startsWith("#") ? text.substring(1) : text)); } catch (NumberFormatException e) { throw new ConversionException(e); } }  @Override Class<? extends Color> getValueType(); @Override Color parse(String text); @Override String format(Color value);  }
@Test public void testParseCommaSeparatedNumbersString() throws ConversionException { assertEquals(Color.WHITE, colorConverter.parse("255,255,255")); assertEquals(Color.BLACK, colorConverter.parse("0,0,0")); assertEquals(Color.decode("0x356463"), colorConverter.parse("53,100,99")); }
@Test(expected = ConversionException.class) public void testParseFaultyExpression_1() throws ConversionException { colorConverter.parse("x"); }
@Test(expected = ConversionException.class) public void testParseFaultyExpression_2() throws ConversionException { colorConverter.parse("white"); }