ColorNameLookup { public Color getColorFromName(String colorStr) { String str = colorStr.trim(); for (ColorName c : colorList) { if (c.getName().equalsIgnoreCase(str)) { return new Color(c.getRed(), c.getGreen(), c.getBlue()); } } return null; } ColorNameLookup(); String getColorNameFromStr(String colorStr); Color getColorFromName(String colorStr);  }
@Test public void testGetColorFromNameBadColorName() { String colorStr = "BadColorName"; System.out.println("GetColorFromNameBadColorName ["+ colorStr +"]"); ColorNameLookup c = new ColorNameLookup(); Color result = c.getColorFromName(colorStr); assertNull(result); }
@Test public void testGetColorFromNameWhite() { String colorStr = "white"; System.out.println("GetColorFromNameWhite ["+ colorStr +"]"); ColorNameLookup c = new ColorNameLookup(); Color expResult = Color.WHITE; Color result = c.getColorFromName(colorStr); assertEquals(expResult, result); }
@Test public void testGetColorFromNameSilver() { String colorStr = "silver"; System.out.println("GetColorFromNameSilver ["+ colorStr +"]"); ColorNameLookup c = new ColorNameLookup(); Color expResult = new Color(192,192,192); Color result = c.getColorFromName(colorStr); assertEquals(expResult, result); }
@Test public void testGetColorFromNameDarkMagenta() { String colorStr = "DarkMagenta"; System.out.println("GetColorFromNameDarkMagenta ["+ colorStr +"]"); ColorNameLookup c = new ColorNameLookup(); Color expResult = new Color(139,0,139); Color result = c.getColorFromName(colorStr); assertEquals(expResult, result); }
@Test public void testGetColorFromNameBadCaseWidthSpaces() { String colorStr = " darkmagenta "; System.out.println("GetColorFromNameBadCaseWidthSpaces ["+ colorStr +"]"); ColorNameLookup c = new ColorNameLookup(); Color expResult = new Color(139,0,139); Color result = c.getColorFromName(colorStr); assertEquals(expResult, result); }