From 931e6c2de13677e0d18d2a05bfd99df398e0ee6b Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 10 Apr 2024 04:27:39 -0400 Subject: [PATCH] Add ServerControllerTests#ensureUnknownPort --- .../braydon/mc/controller/ServerController.java | 2 +- .../java/me/braydon/mc/service/MojangService.java | 2 +- .../mc/test/controller/ServerControllerTests.java | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/braydon/mc/controller/ServerController.java b/src/main/java/me/braydon/mc/controller/ServerController.java index 691a97b..3444a33 100644 --- a/src/main/java/me/braydon/mc/controller/ServerController.java +++ b/src/main/java/me/braydon/mc/controller/ServerController.java @@ -65,7 +65,7 @@ public final class ServerController { * @param hostname the hostname of the server * @param port the port of the server, null for default * @return the server - * @throws BadRequestException if the hostname or platform is invalid + * @throws BadRequestException if the hostname, platform, or port is invalid * @throws ResourceNotFoundException if the server isn't found */ @GetMapping("/{platform}/{hostname}") diff --git a/src/main/java/me/braydon/mc/service/MojangService.java b/src/main/java/me/braydon/mc/service/MojangService.java index 63a9c68..c1d589a 100644 --- a/src/main/java/me/braydon/mc/service/MojangService.java +++ b/src/main/java/me/braydon/mc/service/MojangService.java @@ -347,7 +347,7 @@ public final class MojangService { * @param hostname the hostname of the server * @param portString the port of the server, null for default * @return the resolved Minecraft server - * @throws BadRequestException if the hostname or platform is invalid + * @throws BadRequestException if the hostname, platform, or port is invalid * @throws ResourceNotFoundException if the server isn't found */ @NonNull diff --git a/src/test/java/me/braydon/mc/test/controller/ServerControllerTests.java b/src/test/java/me/braydon/mc/test/controller/ServerControllerTests.java index 8dd35be..4b5737a 100644 --- a/src/test/java/me/braydon/mc/test/controller/ServerControllerTests.java +++ b/src/test/java/me/braydon/mc/test/controller/ServerControllerTests.java @@ -120,6 +120,21 @@ public final class ServerControllerTests { .andReturn(); } + /** + * Run a test to ensure looking up + * an invalid port results in a 400. + * + * @throws Exception if the test fails + */ + @Test + void ensureUnknownPort() throws Exception { + mockMvc.perform(get("/server/java/hypixel.net?port=A") + .accept(MediaType.APPLICATION_JSON) // Accept JSON + .contentType(MediaType.APPLICATION_JSON) // Content type is JSON + ).andExpect(status().isBadRequest()) // Expect 400 (Bad Request) + .andReturn(); + } + /** * Run a test to ensure checking if * a server is banned is successful.