### Question:
BaseConfigurationFactory implements ConfigurationFactory<T, U> { @Override public Pair<T, U> build(ConfigurationSourceProvider provider, String path) throws IOException, ConfigurationException { try (InputStream input = provider.open(requireNonNull(path))) { final JsonNode node = objectMapper.readTree(createParser(input)); if (node == null) { throw ConfigurationParsingException .builder("GJEXConfiguration at " + path + " must not be empty") .build(path); } return build(node, path); } catch (JsonParseException e) { throw ConfigurationParsingException .builder("Malformed " + formatName) .setCause(e) .setLocation(e.getLocation()) .setDetail(e.getMessage()) .build(path); } } BaseConfigurationFactory(JsonFactory parserFactory,
                                    String formatName,
                                    Class<T> klass,
                                    Validator validator,
                                    ObjectMapper objectMapper); @Override Pair<T, U> build(ConfigurationSourceProvider provider, String path); @Override Pair<T, U> build();  }### Answer:
@Test public void throwsAnExceptionOnMalformedFiles() throws Exception { factory.build(malformedFile); failBecauseExceptionWasNotThrown(ConfigurationParsingException.class); }
@Test public void throwsAnExceptionOnEmptyFiles() throws Exception { try { factory.build(emptyFile); failBecauseExceptionWasNotThrown(ConfigurationParsingException.class); } catch (ConfigurationParsingException e) { assertThat(e.getMessage()) .containsOnlyOnce(" * GJEXConfiguration at " + emptyFile.toString() + " must not be empty"); } }
@Test public void incorrectTypeIsFound() throws Exception { assertThatThrownBy(() -> factory.build(wrongTypeFile)) .isInstanceOf(ConfigurationParsingException.class) .hasMessage(String.format("%s has an error:" + NEWLINE + " * Incorrect type of value at: age; is of type: String, expected: int" + NEWLINE, wrongTypeFile)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void loadsValidConfigFiles() throws Exception { final Pair<ExampleConfig, Map> result = factory.build(validFile); ExampleConfig example = result.getKey(); assertThat(example.getName()).isEqualTo("GJEX"); assertThat(example.getAge()).isEqualTo(12); assertThat(example.getProperties()) .contains(MapEntry.entry("k1", "v1"), MapEntry.entry("settings.enabled", "true")); Map<String, Object> configMap = (Map<String, Object>) result.getValue(); assertThat(configMap.size()).isEqualTo(7); }
@Test public void printsDetailedInformationOnMalformedContent() throws Exception { factory.build(malformedAdvancedFile); }