JsonObject extends JsonValue { void maybe(String key, Consumer<JsonValue> consumer) { if (storage.containsKey(key)) { consumer.accept(childFor(key)); } } JsonObject(Map<String, Object> storage); @Override R requireObject(Function<JsonObject, R> mapper); Set<String> keySet(); Object get(String name);  }
@Test public void testMaybeWithConsumer() { Consumer<JsonValue> consumer = mockConsumer(); subject().maybe("a", consumer); verify(consumer).accept(JsonValue.of(true)); }
@Test public void testMaybeWithConsumerMiss() { Consumer<JsonValue> consumer = mockConsumer(); subject().maybe("aaa", consumer); verify(consumer, never()).accept(any()); }