Add more player unit tests
This commit is contained in:
parent
fb7bd3299f
commit
ef36799979
@ -677,6 +677,7 @@
|
|||||||
package me.braydon.mc.test.controller;
|
package me.braydon.mc.test.controller;
|
||||||
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import me.braydon.mc.controller.PlayerController;
|
||||||
import me.braydon.mc.test.config.TestRedisConfig;
|
import me.braydon.mc.test.config.TestRedisConfig;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -690,6 +691,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for the {@link PlayerController}.
|
||||||
|
*
|
||||||
* @author Braydon
|
* @author Braydon
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = TestRedisConfig.class)
|
@SpringBootTest(classes = TestRedisConfig.class)
|
||||||
@ -713,11 +716,11 @@ public final class PlayerControllerTests {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void ensurePlayerLookupSuccess() throws Exception {
|
void ensurePlayerLookupSuccess() throws Exception {
|
||||||
mockMvc.perform(get("/player/Rainnny")
|
mockMvc.perform(get("/player/g")
|
||||||
.accept(MediaType.APPLICATION_JSON) // Accept JSON
|
.accept(MediaType.APPLICATION_JSON) // Accept JSON
|
||||||
.contentType(MediaType.APPLICATION_JSON) // Content type is JSON
|
.contentType(MediaType.APPLICATION_JSON) // Content type is JSON
|
||||||
).andExpect(status().isOk()) // Expect 200 (OK)
|
).andExpect(status().isOk()) // Expect 200 (OK)
|
||||||
.andExpect(jsonPath("$.username").value("Rainnny")) // Expect the player's username
|
.andExpect(jsonPath("$.username").value("g")) // Expect the player's username
|
||||||
.andReturn();
|
.andReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -728,11 +731,41 @@ public final class PlayerControllerTests {
|
|||||||
* @throws Exception if the test fails
|
* @throws Exception if the test fails
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void ensurePlayerLookupFailure() throws Exception {
|
void ensurePlayerNotFound() throws Exception {
|
||||||
mockMvc.perform(get("/player/A")
|
mockMvc.perform(get("/player/SDFSDFSDFSDFDDDG")
|
||||||
.accept(MediaType.APPLICATION_JSON) // Accept JSON
|
.accept(MediaType.APPLICATION_JSON) // Accept JSON
|
||||||
.contentType(MediaType.APPLICATION_JSON) // Content type is JSON
|
.contentType(MediaType.APPLICATION_JSON) // Content type is JSON
|
||||||
).andExpect(status().isNotFound()) // Expect 404 (Not Found)
|
).andExpect(status().isNotFound()) // Expect 404 (Not Found)
|
||||||
.andReturn();
|
.andReturn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a test to ensure retrieving
|
||||||
|
* player's with invalid usernames
|
||||||
|
* results in a 400.
|
||||||
|
*
|
||||||
|
* @throws Exception if the test fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void ensureUsernameIsInvalid() throws Exception {
|
||||||
|
mockMvc.perform(get("/player/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 retrieving
|
||||||
|
* a player's head texture is successful.
|
||||||
|
*
|
||||||
|
* @throws Exception if the test fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void ensureSkinPartTextureSuccess() throws Exception {
|
||||||
|
mockMvc.perform(get("/player/head/Rainnny.png")
|
||||||
|
.contentType(MediaType.IMAGE_PNG) // Content type is PNG
|
||||||
|
).andExpect(status().isOk()) // Expect 200 (OK)
|
||||||
|
.andReturn();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user