ColorProvider { public String getColor(String type) { if (type == null) { return null; } else if (colorMap.containsKey(type.toLowerCase())) { return colorMap.get(type.toLowerCase()); } else if (defaultColorMap.containsKey(type.toLowerCase())) { return defaultColorMap.get(type.toLowerCase()); } else { return defaultColor; } } ColorProvider(SubstitutionScheduleData data);   ColorProvider(); String getColor(String type);  }
@Test public void testPreconfigured() { final SubstitutionScheduleData scheduleData = new SubstitutionScheduleData(); scheduleData.setData(new JSONObject()); final ColorProvider provider = new ColorProvider(scheduleData); assertEquals("#2196F3", provider.getColor("Vertretung")); assertEquals("#9C27B0", provider.getColor("XYZ")); }
@Test public void testCustomName() throws JSONException { final SubstitutionScheduleData scheduleData = new SubstitutionScheduleData(); final JSONObject data = new JSONObject(); final JSONObject colors = new JSONObject(); final JSONArray values = new JSONArray(); values.put("Vertretung"); colors.put("red", values); data.put("colors", colors); scheduleData.setData(data); final ColorProvider provider = new ColorProvider(scheduleData); assertEquals("#F44336", provider.getColor("Vertretung")); }
@Test public void testCustomColor() throws JSONException { final SubstitutionScheduleData scheduleData = new SubstitutionScheduleData(); final JSONObject data = new JSONObject(); final JSONObject colors = new JSONObject(); final JSONArray values = new JSONArray(); values.put("Vertretung"); colors.put("#123456", values); data.put("colors", colors); scheduleData.setData(data); final ColorProvider provider = new ColorProvider(scheduleData); assertEquals("#123456", provider.getColor("Vertretung")); }
@Test public void testCustomDefaultColor() throws JSONException { final SubstitutionScheduleData scheduleData = new SubstitutionScheduleData(); final JSONObject data = new JSONObject(); final JSONObject colors = new JSONObject(); final JSONArray values = new JSONArray(); values.put("_default"); colors.put("#123456", values); data.put("colors", colors); scheduleData.setData(data); final ColorProvider provider = new ColorProvider(scheduleData); assertEquals("#123456", provider.getColor("XYZ")); }