Archived
0

refactoring: Config

YAML -> HOCON
This commit is contained in:
2021-05-11 16:07:46 +03:00
parent 2b9f021419
commit 59b374e623
13 changed files with 152 additions and 151 deletions

View File

@@ -0,0 +1,59 @@
package mc.server.di;
import com.typesafe.config.Config;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.*;
class ConfigModuleTest {
@Test
void singleton() {
ConfigComponent component = DaggerConfigComponent.builder()
.configModule(new ConfigModule(pathResource("/config-1.conf"))).build();
Config config1 = component.getConfig();
Config config2 = component.getConfig();
assertEquals(config1, config2);
assertSame(config1, config2);
}
@Test
void loadConfig() {
ConfigComponent component = DaggerConfigComponent.builder()
.configModule(new ConfigModule(pathResource("/config-1.conf"))).build();
Config config = component.getConfig();
assertEquals("value1", config.getString("key1"));
assertEquals("value2", config.getString("key2.subkey1"));
assertEquals("value3", config.getString("key3.subkey1"));
assertEquals("value4", config.getString("\"key4.somename\""));
assertEquals("value5", config.getString("key5"));
}
@Test
void includeTest() {
ConfigComponent component = DaggerConfigComponent.builder()
.configModule(new ConfigModule(pathResource("/config-2.conf"))).build();
Config config = component.getConfig();
assertEquals("value1", config.getString("key1"));
assertEquals("value2", config.getString("key2.subkey1"));
assertEquals("value3", config.getString("key3.subkey1"));
assertEquals("value4", config.getString("\"key4.somename\""));
assertEquals("value5", config.getString("key5"));
}
@SneakyThrows
private static Path pathResource(String resource) {
URL url = ConfigModuleTest.class.getResource(resource);
assertNotNull(url);
return Paths.get(url.toURI());
}
}