From 9411c5ad41aa36ff74c7de85d9265648b0de336c Mon Sep 17 00:00:00 2001 From: Marten Rebane <54431068+martenrebane@users.noreply.github.com> Date: Mon, 25 Sep 2023 17:14:57 +0300 Subject: [PATCH] Test fix --- .../ConfigurationPropertiesTest.java | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/configuration-lib/src/test/java/ee/ria/DigiDoc/configuration/ConfigurationPropertiesTest.java b/configuration-lib/src/test/java/ee/ria/DigiDoc/configuration/ConfigurationPropertiesTest.java index 38b0ab1b1..46e90b1bf 100644 --- a/configuration-lib/src/test/java/ee/ria/DigiDoc/configuration/ConfigurationPropertiesTest.java +++ b/configuration-lib/src/test/java/ee/ria/DigiDoc/configuration/ConfigurationPropertiesTest.java @@ -14,6 +14,8 @@ import java.io.IOException; import java.io.InputStream; +import java.util.Objects; +import java.util.Optional; @RunWith(MockitoJUnitRunner.class) public class ConfigurationPropertiesTest { @@ -23,23 +25,18 @@ public class ConfigurationPropertiesTest { @Test public void loadProperties() throws IOException { - ClassLoader classLoader = getClass().getClassLoader(); - if (classLoader != null) { - try (InputStream inputStream = classLoader.getResourceAsStream(ConfigurationProperties.PROPERTIES_FILE_NAME); - InputStream assetStream = assetManager.open(anyString())) { - if (inputStream != null) { - when(assetStream).thenReturn(inputStream); - - ConfigurationProperties configurationProperties = new ConfigurationProperties(assetManager); - - assertEquals("https://id.eesti.ee/", configurationProperties.getCentralConfigurationServiceUrl()); - assertSame(4, configurationProperties.getConfigurationUpdateInterval()); - } else { - throw new IllegalStateException("Unable to get properties file name"); - } - } - } else { - throw new IllegalStateException("Unable to get ClassLoader"); + ClassLoader classLoader = Optional.ofNullable(getClass().getClassLoader()) + .orElseThrow(() -> new IllegalStateException("Unable to get ClassLoader")); + try (InputStream inputStream = Objects.requireNonNull( + classLoader.getResourceAsStream(ConfigurationProperties.PROPERTIES_FILE_NAME), + "Unable to open properties file" + )) { + when(assetManager.open(anyString())).thenReturn(inputStream); + + ConfigurationProperties configurationProperties = new ConfigurationProperties(assetManager); + + assertEquals("https://id.eesti.ee/", configurationProperties.getCentralConfigurationServiceUrl()); + assertSame(4, configurationProperties.getConfigurationUpdateInterval()); } } }