ColorConverter { public static Color colorFromColorName(String colorStr) { String str = colorStr.replaceAll("\\s", ""); ColorNameLookup c = new ColorNameLookup(); return c.getColorFromName(str); } private  ColorConverter(); static Color offsetHsbColor(Color color, float offsetHue, float offsetSaturation, float offsetBrightness); static Float getBrightness(Color color); static Float getSaturation(Color color); static Float getHue(Color color); static Color offsetRgbColor(Color bgColor, int offsetRed, int offsetGreen, int offsetBlue); static String formatColorStr(String colorStr); static Color colorFromStr(String colorStr); static Color colorFromColorName(String colorStr); static Color colorFromRgbStr(String colorStr); static Color hex2Rgb(String colorStr); static String hex2Rgb(Color color); static String rgb2Hex(Color color); static String rgb2Hsl(Color color);  }
@Test public void testColorFromStrBadValue() { System.out.println("------------ ColorFromStr BAD value ----------------"); String colorStr; Color result; Color expResult; colorStr = "256,0,0"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = "rgb(256,0,0)"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = "rgb(256,0,0"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = "FF"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = "FFFFFFFFFFFFF"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = "#FF"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = "#FFFFFFFFFFFFF"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = "badColorName_WHITE"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = ""; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); System.out.println("--------------------------"); }
@Test public void testColorFromColorName() { System.out.println("------------ colorFromColorName ----------------"); String colorStr; Color result; Color expResult; colorStr = " wHite "; expResult = Color.WHITE; result = ColorConverter.colorFromColorName(colorStr); assertEquals(expResult, result); System.out.println("colorFromColorName ["+ colorStr +"]"); colorStr = " BlaCK "; expResult = Color.BLACK; result = ColorConverter.colorFromColorName(colorStr); assertEquals(expResult, result); System.out.println("colorFromColorName ["+ colorStr +"]"); colorStr = "darkmagenta"; expResult = new Color(139,0,139); result = ColorConverter.colorFromColorName(colorStr); assertEquals(expResult, result); System.out.println("colorFromColorName ["+ colorStr +"]"); System.out.println("--------------------------"); }
@Test public void testColorFromColorNameBadValue() { System.out.println("------------ colorFromColorName BAD value----------------"); String colorStr; Color result; colorStr = "badColorName_WHITE"; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); colorStr = ""; result = ColorConverter.colorFromColorName(colorStr); assertNull(result); System.out.println("colorFromColorName BAD value ["+ colorStr +"]"); System.out.println("--------------------------"); }