DepictController { static Color getColor(String color) { int vals[] = new int[]{0,0,0,255}; int pos = 0; int beg = 0; if (color.startsWith("0x")) beg = 2; else if (color.startsWith("#")) beg = 1; for (; pos < 4 && beg+1 < color.length(); beg += 2) { vals[pos++] = Integer.parseInt(color.substring(beg,beg+2), 16); } return new Color(vals[0], vals[1], vals[2], vals[3]); } DepictController(); @RequestMapping("depict/{style}/{fmt}") HttpEntity<?> depict(@RequestParam("smi") String smi,
                              @PathVariable("fmt") String fmt,
                              @PathVariable("style") String style,
                              @RequestParam Map<String,String> extra);  }
@Test public void getColor() throws Exception { Color color = DepictController.getColor("#ff00ff"); assertThat(color.getRed(), is(255)); assertThat(color.getGreen(), is(0)); assertThat(color.getBlue(), is(255)); assertThat(color.getAlpha(), is(255)); }
@Test public void getColorTruncated() throws Exception { Color color = DepictController.getColor("#ff00f"); assertThat(color.getRed(), is(255)); assertThat(color.getGreen(), is(0)); assertThat(color.getBlue(), is(0)); assertThat(color.getAlpha(), is(255)); }
@Test public void getColorTooLong() throws Exception { Color color = DepictController.getColor("#ff00ffffff"); assertThat(color.getRed(), is(255)); assertThat(color.getGreen(), is(0)); assertThat(color.getBlue(), is(255)); assertThat(color.getAlpha(), is(255)); }