#39 Fixed tests and added some more

This commit is contained in:
Marvin Scham
2023-05-24 01:04:13 +02:00
parent da1cad1a59
commit ffc804aba1
7 changed files with 138 additions and 59 deletions

View File

@@ -2,24 +2,15 @@ package de.rwu.easydrop.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.spy;
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import javax.naming.ConfigurationException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
class ConfigTest {
@Mock
private FileInputStream mockFileInputStream;
private Config config;
@BeforeEach
@@ -28,59 +19,24 @@ class ConfigTest {
config = spy(Config.getInstance());
}
@Test
void testGetProperty_ExistingKey() throws NoSuchElementException {
config.setProperty("API_KEY", "12345");
String value = config.getProperty("API_KEY");
assertEquals("12345", value);
}
@Test
void testGetProperty_NonExistingKey() {
assertThrows(NoSuchElementException.class, () -> config.getProperty("NON_EXISTING_KEY"));
}
@Test
void testSetProperty() {
config.setProperty("API_KEY", "12345");
assertEquals("12345", config.getProperty("API_KEY"));
}
@Test
void testGetInstanceNull() {
config = null;
try {
Config newConfig = Config.getInstance();
// Check if the returned instance is not null
assertNotNull(newConfig);
} catch (ConfigurationException e) {
fail("ConfigurationException should not be thrown.");
}
Config newConfig = Config.getInstance();
assertNotNull(newConfig);
}
@Test
void testGetInstanceNotNull() {
try {
Config newConfig = Config.getInstance();
// Check if the returned instance is not null
assertNotNull(newConfig);
} catch (ConfigurationException e) {
fail("ConfigurationException should not be thrown.");
}
Config newConfig = Config.getInstance();
assertNotNull(newConfig);
}
@Test
void testLoadConfigSuccessfully() {
try {
config.loadConfig();
config.setProperty("WHATEVER", "SUCCESS");
assertNotNull(config.getProperty("WHATEVER"));
} catch (ConfigurationException e) {
fail("ConfigurationException should not be thrown");
}
void testSetConfigLocation() {
String newPath = "new/location/config.properties";
config.setConfigLocation(newPath);
assertEquals(newPath, config.getConfigLocation());
}
}