MultiFormatJsonNodeParser implements Function<URL, Optional<JsonNode>> { ParserType parserTypeFromExtension(URL url) { String path = url.getPath(); if (path == null) { return null; } int dot = path.lastIndexOf('.'); if (dot < 0 || dot == path.length() - 1) { return null; } switch (path.substring(dot + 1)) { case "yml": case "yaml": bootLogger.trace(() -> "Configuration is in YAML format (based on URL extension)"); return ParserType.YAML; case "json": bootLogger.trace(() -> "Configuration is in JSON format (based on URL extension)"); return ParserType.JSON; default: return null; } } MultiFormatJsonNodeParser(Map<ParserType, Function<InputStream, Optional<JsonNode>>> parsers, BootLogger bootLogger); @Override Optional<JsonNode> apply(URL url);  }
@Test public void testParserTypeFromExtension_Unknown() throws MalformedURLException { MultiFormatJsonNodeParser parser = new MultiFormatJsonNodeParser(Collections.emptyMap(), mock(BootLogger.class)); assertNull(parser.parserTypeFromExtension(new URL("http: assertNull(parser.parserTypeFromExtension(new URL("http: assertNull(parser.parserTypeFromExtension(new URL("http: }
@Test public void testParserTypeFromExtension() throws MalformedURLException { MultiFormatJsonNodeParser parser = new MultiFormatJsonNodeParser(Collections.emptyMap(), mock(BootLogger.class)); assertEquals(ParserType.YAML, parser.parserTypeFromExtension(new URL("http: assertEquals(ParserType.YAML, parser.parserTypeFromExtension(new URL("http: assertEquals(ParserType.JSON, parser.parserTypeFromExtension(new URL("http: }
@Test public void testParserTypeFromExtension_IgnoreQuery() throws MalformedURLException { MultiFormatJsonNodeParser parser = new MultiFormatJsonNodeParser(Collections.emptyMap(), mock(BootLogger.class)); assertEquals(ParserType.JSON, parser.parserTypeFromExtension(new URL("http: }
@Test public void testParserTypeFromExtension_FileUrl() throws MalformedURLException { MultiFormatJsonNodeParser parser = new MultiFormatJsonNodeParser(Collections.emptyMap(), mock(BootLogger.class)); assertEquals(ParserType.YAML, parser.parserTypeFromExtension(new URL("file: }