refactoring: реорганизация загрузки конфигураций
This commit is contained in:
@@ -12,10 +12,15 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ConfigModuleTest {
|
||||
|
||||
private static final String emptyConfig = "./config-empty.conf";
|
||||
|
||||
/*
|
||||
Проверяем, что загруженный объект конфига является singleton
|
||||
*/
|
||||
@Test
|
||||
void singleton() {
|
||||
ConfigComponent component = DaggerConfigComponent.builder()
|
||||
.configModule(new ConfigModule(pathResource("/config-1.conf"))).build();
|
||||
.configModule(new ConfigModule(emptyConfig, pathResource("/config-1.conf"))).build();
|
||||
Config config1 = component.getConfig();
|
||||
Config config2 = component.getConfig();
|
||||
|
||||
@@ -23,10 +28,13 @@ class ConfigModuleTest {
|
||||
assertSame(config1, config2);
|
||||
}
|
||||
|
||||
/*
|
||||
Корректная загрузка конфига
|
||||
*/
|
||||
@Test
|
||||
void loadConfig() {
|
||||
ConfigComponent component = DaggerConfigComponent.builder()
|
||||
.configModule(new ConfigModule(pathResource("/config-1.conf"))).build();
|
||||
.configModule(new ConfigModule(emptyConfig, pathResource("/config-1.conf"))).build();
|
||||
|
||||
Config config = component.getConfig();
|
||||
assertEquals("value1", config.getString("key1"));
|
||||
@@ -36,10 +44,13 @@ class ConfigModuleTest {
|
||||
assertEquals("value5", config.getString("key5"));
|
||||
}
|
||||
|
||||
/*
|
||||
Проверка include
|
||||
*/
|
||||
@Test
|
||||
void includeTest() {
|
||||
ConfigComponent component = DaggerConfigComponent.builder()
|
||||
.configModule(new ConfigModule(pathResource("/config-2.conf"))).build();
|
||||
.configModule(new ConfigModule(emptyConfig, pathResource("/config-2.conf"))).build();
|
||||
|
||||
Config config = component.getConfig();
|
||||
assertEquals("value1", config.getString("key1"));
|
||||
@@ -49,6 +60,31 @@ class ConfigModuleTest {
|
||||
assertEquals("value5", config.getString("key5"));
|
||||
}
|
||||
|
||||
/*
|
||||
Работа с многострочностью
|
||||
*/
|
||||
@Test
|
||||
void multilineTest() {
|
||||
ConfigComponent component = DaggerConfigComponent.builder()
|
||||
.configModule(new ConfigModule(emptyConfig, pathResource("/config-1.conf"))).build();
|
||||
|
||||
Config config = component.getConfig();
|
||||
assertEquals("line1\nline2", config.getString("key6"));
|
||||
}
|
||||
|
||||
/*
|
||||
Проверяем работу merge config
|
||||
*/
|
||||
@Test
|
||||
void mergeConfigTest() {
|
||||
ConfigComponent component = DaggerConfigComponent.builder()
|
||||
.configModule(new ConfigModule("./config-1.conf", pathResource("/config-3.conf"))).build();
|
||||
Config config = component.getConfig();
|
||||
|
||||
assertEquals("value1_merged", config.getString("key1"));
|
||||
assertEquals("value2", config.getString("key2.subkey1"));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static Path pathResource(String resource) {
|
||||
URL url = ConfigModuleTest.class.getResource(resource);
|
||||
|
||||
Reference in New Issue
Block a user