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
This commit is contained in:
Christian Koop 2022-04-27 22:53:06 +02:00
parent 6d6fa7210a
commit 8f15df3601
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
2 changed files with 0 additions and 44 deletions

View File

@ -59,17 +59,6 @@ public interface IConfiguration {
*/ */
void reset(); 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. * 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. * 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; 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. * 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). * Additional data may be written depending on the implementation (e.g. comments).

View File

@ -5,13 +5,10 @@ import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.constructor.DuplicateKeyException; import org.yaml.snakeyaml.constructor.DuplicateKeyException;
import org.yaml.snakeyaml.error.YAMLException; import org.yaml.snakeyaml.error.YAMLException;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -510,25 +507,6 @@ class YamlConfigurationTest {
assertTrue(secondToString.contains(cfg.values.toString())); 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 @Test
void testLoadWithInvalidYaml() { void testLoadWithInvalidYaml() {
final YamlConfiguration cfg = new YamlConfiguration(); final YamlConfiguration cfg = new YamlConfiguration();