From 8f15df3601c2309c394933d5529dd4712bec49ca Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Wed, 27 Apr 2022 22:53:06 +0200 Subject: [PATCH] Removes the default implementations for #save(File) and #load(File) Overwriting an implementing class quickly becomes a potential hassle as there is no guarantee how they are implementend #41 --- .../core/configuration/IConfiguration.java | 22 ------------------- .../yaml/YamlConfigurationTest.java | 22 ------------------- 2 files changed, 44 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/configuration/IConfiguration.java b/Core/src/main/java/com/songoda/core/configuration/IConfiguration.java index c964806c..20f81164 100644 --- a/Core/src/main/java/com/songoda/core/configuration/IConfiguration.java +++ b/Core/src/main/java/com/songoda/core/configuration/IConfiguration.java @@ -59,17 +59,6 @@ public interface IConfiguration { */ void reset(); - /** - * This method does the same as {@link #load(Reader)} but takes in a File. - * By default, this implementation wraps the given file in a {@link FileReader} and calls {@link #load(Reader)}. - * - * @throws FileNotFoundException Thrown by {@link FileReader#FileReader(File)} - * @see #load(Reader) - */ - default void load(File file) throws IOException { - load(new FileReader(file)); - } - /** * This method parses and loads the configuration and stores them as key-value pairs in memory. * Keys that are not loaded with this call but still exist in memory, are removed. @@ -79,17 +68,6 @@ public interface IConfiguration { */ void load(Reader reader) throws IOException; - /** - * This method does the same as {@link #save(Writer)} but takes in a File. - * By default, this implementation wraps the given file in a {@link FileWriter} and calls {@link #save(Writer)}. - * - * @throws FileNotFoundException Thrown by {@link FileWriter#FileWriter(File)} - * @see #load(Reader) - */ - default void save(File file) throws IOException { - save(new FileWriter(file)); - } - /** * This method serializes the key-value pairs in memory and writes them to the given writer. * Additional data may be written depending on the implementation (e.g. comments). diff --git a/Core/src/test/java/com/songoda/core/configuration/yaml/YamlConfigurationTest.java b/Core/src/test/java/com/songoda/core/configuration/yaml/YamlConfigurationTest.java index 9b7ea7dd..bd25577d 100644 --- a/Core/src/test/java/com/songoda/core/configuration/yaml/YamlConfigurationTest.java +++ b/Core/src/test/java/com/songoda/core/configuration/yaml/YamlConfigurationTest.java @@ -5,13 +5,10 @@ import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.constructor.DuplicateKeyException; import org.yaml.snakeyaml.error.YAMLException; -import java.io.File; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -510,25 +507,6 @@ class YamlConfigurationTest { assertTrue(secondToString.contains(cfg.values.toString())); } - @Test - void testSaveAndLoadToFile() throws IOException { - final YamlConfiguration cfg = new YamlConfiguration(); - cfg.load(new StringReader(inputYaml)); - - File tmpFile = Files.createTempFile(this.getClass().getName(), "yml").toFile(); - tmpFile.deleteOnExit(); - - cfg.save(tmpFile); - - assertArrayEquals(expectedOutYaml.getBytes(StandardCharsets.UTF_8), Files.readAllBytes(tmpFile.toPath())); - - final YamlConfiguration loadedCfg = new YamlConfiguration(); - loadedCfg.set("should-be-overwritten", "foo"); - loadedCfg.load(tmpFile); - - assertEquals(cfg.values, loadedCfg.values); - } - @Test void testLoadWithInvalidYaml() { final YamlConfiguration cfg = new YamlConfiguration();