DockerComposeRuleConfig { @VisibleForTesting static Optional<DockerComposeRuleConfig> findAutomaticallyFrom(File startDir) { Optional<File> configFile = dirAndParents(startDir) .map(dir -> new File(dir, CONFIG_FILENAME)) .findFirst(File::exists); return configFile.map(config -> { try { return OBJECT_MAPPER.readValue(config, DockerComposeRuleConfig.class); } catch (IOException e) { throw new RuntimeException("Couldn't deserialize config file", e); } }); }  abstract Optional<ReportingConfig> reporting(); static Builder builder(); static Optional<DockerComposeRuleConfig> findAutomatically(); static final String CONFIG_FILENAME; }
@Test public void optional_empty_when_config_does_not_exist() { assertThat(DockerComposeRuleConfig.findAutomaticallyFrom(temporaryFolder.getRoot())).isEmpty(); }
@Test public void throws_when_config_file_is_invalid() throws IOException { File config = temporaryFolder.newFile(".docker-compose-rule.yml"); Files.write(config.toPath(), ImmutableList.of( "reporting:", " whoops: oh no" ), StandardCharsets.UTF_8); assertThatExceptionOfType(RuntimeException.class) .isThrownBy(() -> DockerComposeRuleConfig.findAutomaticallyFrom(temporaryFolder.getRoot())) .withMessageContaining("deserialize config file"); }