JsonObject extends JsonValue { void require(String key, Consumer<JsonValue> consumer) { if (storage.containsKey(key)) { consumer.accept(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 testRequireWithConsumer() { Consumer<JsonValue> consumer = mockConsumer(); subject().require("a", consumer); verify(consumer).accept(JsonValue.of(true)); }
@Test public void testRequireWithConsumerFailure() { expExc.expect(SchemaException.class); expExc.expectMessage("#: required key [aaa] not found"); Consumer<JsonValue> consumer = mockConsumer(); subject().require("aaa", consumer); verify(consumer, never()).accept(any()); }