refactoring: Config
YAML -> HOCON
This commit is contained in:
59
server-new/src/test/java/mc/server/di/ConfigModuleTest.java
Normal file
59
server-new/src/test/java/mc/server/di/ConfigModuleTest.java
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user