added some tests

This commit is contained in:
Mei Chang van der Werff 2026-01-16 16:30:37 +01:00
commit 61562d58dc
3 changed files with 104 additions and 11 deletions

View file

@ -30,10 +30,9 @@ public class PortChecker {
public boolean isPortAvailable(int port){
try(ServerSocket socket = new ServerSocket(port)){
return true;
}catch(IOException i) {
}
catch(IOException i) {
return false;
}
}
}
}

View file

@ -1,4 +1,3 @@
package server;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
@ -6,7 +5,8 @@ import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.stereotype.Component;
@Component
public class ServerPortCustomizer implements WebServerFactoryCustomizer<ConfigurableWebServerFactory>{
public class ServerPortCustomizer
implements WebServerFactoryCustomizer<ConfigurableWebServerFactory>{
/**
* Changes the port that will be used to launch the program.
* made with the help of: https://www.baeldung.com/spring-boot-change-port
@ -19,11 +19,9 @@ public class ServerPortCustomizer implements WebServerFactoryCustomizer<Configur
int port = portChecker.findFreePort();
factory.setPort(port);
System.out.println("Server starts on port: " + port);
} catch (Exception e) {
}
catch (Exception e) {
throw new RuntimeException("Failed to find a free port", e);
}
}
}
}