TokenParser { public static Color parseColor(String token, Color defaultValue) { final String trimmedToken = token.trim(); if (isWildcard(trimmedToken)) { return defaultValue; } return new Color(Integer.parseInt(trimmedToken, 16)); }  static int parseHex(String token, int defaultValue); static double parseDouble(String token, double defaultValue); static Color parseColor(String token, Color defaultValue); static boolean parseBoolean(String token, boolean defaultValue);  }
@Test public void testParseColorWithDefault() { Color color = TokenParser.parseColor("7766343", Color.BLACK); assertEquals("java.awt.Color[r=118,g=99,b=67]", color.toString()); color = TokenParser.parseColor(" 7766344 ", Color.BLUE); assertEquals("java.awt.Color[r=118,g=99,b=68]", color.toString()); color = TokenParser.parseColor("*", Color.CYAN); assertEquals(Color.CYAN, color); color = TokenParser.parseColor(" * ", Color.DARK_GRAY); assertEquals(Color.DARK_GRAY, color); }