JsonObject extends JsonValue { <R> R requireMapping(String key, Function<JsonValue, R> fn) { if (storage.containsKey(key)) { return fn.apply(childFor(key)); } else { throw failureOfMissingKey(key); } } JsonObject(Map<String, Object> storage); @Override R requireObject(Function<JsonObject, R> mapper); Set<String> keySet(); Object get(String name);  }
@Test public void testRequireWithFunction() { Function<JsonValue, Boolean> fn = val -> false; assertFalse(subject().requireMapping("a", fn)); }
@Test public void testRequireWithFunctionFailure() { expExc.expect(SchemaException.class); expExc.expectMessage("#: required key [aaa] not found"); subject().requireMapping("aaa", val -> false); }