### Question:
GuiPlotColorDecoder { public Object encodeForBrowser(Object board) { if (board instanceof String) { return encode((String)board); } if (!(board instanceof JSONObject)) { throw new IllegalArgumentException("You can use only String or JSONObject as board"); } JSONObject result = (JSONObject)board; String key = "layers"; if (!result.has(key)) { return result; } JSONArray encoded = new JSONArray(); for (Object layer : result.getJSONArray(key)) { encoded.put(encode((String)layer)); } result.put(key, encoded); return result; }  String encodeForClient(Object board); Object encodeForBrowser(Object board); @Override String toString(); static Collector<Character, StringBuilder, String> asString(); static String GUI; }### Answer:
@Test public void shouldEncode() { GuiPlotColorDecoder decoder = new GuiPlotColorDecoder(Elements.values()); assertEquals("ABCD", decoder.encodeForBrowser("1234")); assertEquals("DCBA", decoder.encodeForBrowser("4321")); }
@Test public void shouldEncodeUnexpectedObject() { GuiPlotColorDecoder decoder = new GuiPlotColorDecoder(Elements.values()); try { decoder.encodeForBrowser(Boolean.TRUE); fail("Expected exception"); } catch (IllegalArgumentException e) { Assert.assertEquals("You can use only String or JSONObject as board", e.getMessage()); } }
@Test public void shouldNotEnumSymbol() { GuiPlotColorDecoder decoder = new GuiPlotColorDecoder(Elements.values()); try { decoder.encodeForBrowser("12345"); fail("Expected exception"); } catch (IllegalArgumentException e) { Assert.assertEquals("Not enum symbol '5'", e.getMessage()); } }