MultiFormatJsonNodeParser implements Function<URL, Optional<JsonNode>> { Function<InputStream, Optional<JsonNode>> parser(ParserType type) { Function<InputStream, Optional<JsonNode>> parser = parsers.get(type); if (parser == null) { bootLogger.trace(() -> "No parser for type: " + type); throw new IllegalStateException("Can't find configuration parser for the format: " + type); } return parser; } MultiFormatJsonNodeParser(Map<ParserType, Function<InputStream, Optional<JsonNode>>> parsers, BootLogger bootLogger); @Override Optional<JsonNode> apply(URL url);  }
@Test public void testParser() { Map<ParserType, Function<InputStream, Optional<JsonNode>>> parsers = createParsersMap(ParserType.JSON, ParserType.YAML); MultiFormatJsonNodeParser parser = new MultiFormatJsonNodeParser(parsers, mock(BootLogger.class)); assertSame(parsers.get(ParserType.YAML), parser.parser(ParserType.YAML)); assertSame(parsers.get(ParserType.JSON), parser.parser(ParserType.JSON)); }
@Test public void testParser_MissingYaml() { Map<ParserType, Function<InputStream, Optional<JsonNode>>> parsers = createParsersMap(ParserType.JSON); assertThrows(IllegalStateException.class, () -> new MultiFormatJsonNodeParser(parsers, mock(BootLogger.class)).parser(ParserType.YAML)); }