test: fix all compilation errors and achieve coverage

This commit is contained in:
2026-05-17 09:29:31 +07:00
parent 1e709c51d3
commit 2617ccacb2
13 changed files with 58 additions and 20 deletions
@@ -10,8 +10,10 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import com.walkguide.security.JwtAuthFilter;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
@@ -28,10 +30,13 @@ import static org.springframework.security.test.web.servlet.request.SecurityMock
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@AutoConfigureMockMvc(addFilters = false)
@WebMvcTest(PairingController.class)
@DisplayName("PairingController Unit Tests")
class PairingControllerTest {
@MockBean private JwtAuthFilter jwtAuthFilter;
@Autowired
private MockMvc mockMvc;
@@ -214,6 +219,7 @@ class PairingControllerTest {
void status_asUser_shouldReturn200() throws Exception {
try (MockedStatic<SecurityHelper> sh = mockStatic(SecurityHelper.class)) {
sh.when(SecurityHelper::getCurrentUserId).thenReturn(1L);
sh.when(SecurityHelper::getCurrentUserRole).thenReturn("ROLE_USER");
PairingStatusResponse resp = buildPairingStatus("ACTIVE");
when(pairingService.getStatus(eq(1L), eq("ROLE_USER"))).thenReturn(resp);
@@ -233,6 +239,7 @@ class PairingControllerTest {
void status_asGuardian_shouldReturn200() throws Exception {
try (MockedStatic<SecurityHelper> sh = mockStatic(SecurityHelper.class)) {
sh.when(SecurityHelper::getCurrentUserId).thenReturn(2L);
sh.when(SecurityHelper::getCurrentUserRole).thenReturn("ROLE_GUARDIAN");
PairingStatusResponse resp = buildPairingStatus("ACTIVE");
when(pairingService.getStatus(eq(2L), eq("ROLE_GUARDIAN"))).thenReturn(resp);
@@ -249,6 +256,7 @@ class PairingControllerTest {
void status_noPairing_shouldReturnNoneStatus() throws Exception {
try (MockedStatic<SecurityHelper> sh = mockStatic(SecurityHelper.class)) {
sh.when(SecurityHelper::getCurrentUserId).thenReturn(1L);
sh.when(SecurityHelper::getCurrentUserRole).thenReturn("ROLE_USER");
PairingStatusResponse resp = PairingStatusResponse.builder()
.status("NONE")