ViccDatamodelChecker { boolean check(@NotNull JsonObject object) { boolean correct = true; Set<String> keys = object.keySet(); for (String key : keys) { if (!datamodel.containsKey(key)) { LOGGER.warn("JSON object contains key '{}' which is not expected for '{}'", key, name); correct = false; } } for (Map.Entry<String, Boolean> datamodelEntry : datamodel.entrySet()) { Boolean isMandatory = datamodelEntry.getValue(); assert isMandatory != null; if (isMandatory && !keys.contains(datamodelEntry.getKey())) { LOGGER.warn("Mandatory key '{}' missing from JSON object in '{}'", datamodelEntry.getKey(), name); correct = false; } } return correct; } ViccDatamodelChecker(@NotNull final String name, @NotNull final Map<String, Boolean> datamodel);   }
@Test public void checkingWorksAsExpected() { Map<String, Boolean> map = Maps.newHashMap(); map.put("A", true); map.put("B", false); ViccDatamodelChecker checker = new ViccDatamodelChecker("test", map); JsonObject object = new JsonObject(); assertFalse(checker.check(object)); object.addProperty("A", "test A"); assertTrue(checker.check(object)); object.addProperty("B", "test B"); assertTrue(checker.check(object)); object.addProperty("C", "test C"); assertFalse(checker.check(object)); }