Skip to content
Snippets Groups Projects
Commit a9102368 authored by Martin Vogel's avatar Martin Vogel
Browse files

refactor(config): add test for loading config from path

parent 214eab3b
No related branches found
No related tags found
No related merge requests found
......@@ -2,10 +2,12 @@ package dev.fitko.fitconnect.client.factory;
import dev.fitko.fitconnect.api.config.ApplicationConfig;
import dev.fitko.fitconnect.api.config.Environment;
import dev.fitko.fitconnect.api.config.EnvironmentName;
import dev.fitko.fitconnect.api.config.SenderConfig;
import dev.fitko.fitconnect.api.exceptions.InitializationException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.io.IOException;
......@@ -16,6 +18,7 @@ import java.util.Objects;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class ApplicationConfigLoaderTest {
......@@ -62,6 +65,22 @@ class ApplicationConfigLoaderTest {
assertThat(testConfig.getSenderConfig(), equalTo(senderConfig));
}
@Test
void testLoadTestConfigFromPath(@TempDir final Path tempDir) throws IOException {
// Given
final String testConfigYaml = getResourceAsString("test-config.yml");
final Path configPath = Files.writeString(Path.of(tempDir.toString(), "test-config.yml"), testConfigYaml);
// When
final ApplicationConfig testConfig = ApplicationConfigLoader.loadConfig(configPath);
// Then
assertNotNull(testConfig);
assertThat(testConfig.getActiveEnvironment(), is(new EnvironmentName("dev")));
}
private String getResourceAsString(final String name) throws IOException {
final ClassLoader classLoader = getClass().getClassLoader();
final File file = new File(Objects.requireNonNull(classLoader.getResource(name)).getFile());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment