61 lines
1.7 KiB
Java
61 lines
1.7 KiB
Java
package ch.fritteli.labyrinth.server;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
class ServerConfigTest {
|
|
@BeforeEach
|
|
void clearSysProperties() {
|
|
System.clearProperty(ServerConfig.SYSPROP_HOST);
|
|
System.clearProperty(ServerConfig.SYSPROP_PORT);
|
|
}
|
|
|
|
@Test
|
|
void testInit_noProperties() throws ConfigurationException {
|
|
|
|
// act
|
|
final ServerConfig sut = ServerConfig.init();
|
|
|
|
// assert
|
|
assertEquals("127.0.0.1", sut.getAddress().getHostAddress());
|
|
assertEquals("localhost", sut.getAddress().getHostName());
|
|
assertEquals(0, sut.getPort());
|
|
}
|
|
|
|
@Test
|
|
void testInit_unparseablePort() {
|
|
// arrange
|
|
System.setProperty(ServerConfig.SYSPROP_PORT, "Hello World!");
|
|
|
|
// act / assert
|
|
assertThrows(ConfigurationException.class, ServerConfig::init);
|
|
}
|
|
|
|
@Test
|
|
void testInit_invalidPort() {
|
|
// arrange
|
|
System.setProperty(ServerConfig.SYSPROP_PORT, "99999");
|
|
|
|
// act / assert
|
|
assertThrows(ConfigurationException.class, ServerConfig::init);
|
|
}
|
|
|
|
@Test
|
|
void testInit() throws ConfigurationException, UnknownHostException {
|
|
// arrange
|
|
System.setProperty(ServerConfig.SYSPROP_HOST, "127.0.0.1");
|
|
System.setProperty(ServerConfig.SYSPROP_PORT, "12345");
|
|
|
|
// act
|
|
final ServerConfig sut = ServerConfig.init();
|
|
|
|
// assert
|
|
assertEquals("127.0.0.1", sut.getAddress().getHostAddress());
|
|
assertEquals(12345, sut.getPort());
|
|
}
|
|
}
|