Skip to content
Snippets Groups Projects
Commit 3042aa19 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

test: add unit tests for PlayerController and ShopController

- Add PlayerControllerTest to verify retrieval of all players and individual player by UUID.
- Add ShopControllerTest to verify retrieval of all shops and individual shop by item name.
parent a0e8ea22
No related branches found
No related tags found
No related merge requests found
Checking pipeline status
package com.slprojects.democultureconceptsinfo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;
import java.util.UUID;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@WebMvcTest(PlayerController.class)
public class PlayerControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void testGetAllPlayers() throws Exception {
mockMvc.perform(get("/players"))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0].username").value("JohnDoe"));
}
@Test
public void testGetPlayer() throws Exception {
UUID uuid = PlayerService.firstFakePlayer.getUuid();
mockMvc.perform(get("/player").param("uuid", uuid.toString()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.username").value("JohnDoe"));
}
}
package com.slprojects.democultureconceptsinfo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@WebMvcTest(ShopController.class)
public class ShopControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void testGetAllShops() throws Exception {
mockMvc.perform(get("/shops"))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("$[0].itemName").value("Sword"));
}
@Test
public void testGetShop() throws Exception {
mockMvc.perform(get("/shop").param("itemName", "Sword"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.itemName").value("Sword"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment