|
14 | 14 | import java.net.URI; |
15 | 15 | import java.time.Instant; |
16 | 16 | import java.util.Collections; |
| 17 | +import org.junit.jupiter.api.Disabled; |
17 | 18 | import org.junit.jupiter.api.Test; |
18 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
19 | 20 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
|
28 | 29 | * @author Thomas Turrell-Croft |
29 | 30 | * @author István Rátkai (Selindek) |
30 | 31 | */ |
31 | | -@WebMvcTest(value = {StatementController.class}, |
| 32 | +@WebMvcTest(value = {StatementController.class, ServerControllerAdvice.class}, |
32 | 33 | properties = "spring.jackson.deserialization.ACCEPT_SINGLE_VALUE_AS_ARRAY = true") |
33 | 34 | class StatementControllerTest { |
34 | 35 |
|
@@ -104,22 +105,20 @@ void whenGettingStatementsWithMoreTokenThenStatusIsOk() throws Exception { |
104 | 105 | .andExpect(status().isOk()); |
105 | 106 | } |
106 | 107 |
|
107 | | - // TODO: Fix this test - @MockitoBean with @WebMvcTest isn't throwing exception as expected |
108 | | - // The mock returns 200 OK instead of throwing IllegalArgumentException. This may be related to |
109 | | - // Spring Boot 3.4+ bean override mechanism changes. Try: @MockBean, explicit mock configuration, |
110 | | - // or integration test approach instead of slice test. |
111 | | - // @Test |
112 | | - // void whenGettingStatementsWithInvalidMoreTokenThenStatusIsBadRequest() throws Exception { |
113 | | - // |
114 | | - // // Given Invalid More Token |
115 | | - // doThrow(new IllegalArgumentException()).when(statementService).getStatementsMore("invalid"); |
116 | | - // |
117 | | - // // When Getting Statements With Invalid More Token |
118 | | - // mvc.perform(get("/xapi/statements?more=invalid")) |
119 | | - // |
120 | | - // // Then Status Is Bad Request |
121 | | - // .andExpect(status().isBadRequest()); |
122 | | - // } |
| 108 | + @Disabled("Mock not throwing exception as expected with @MockitoBean and @WebMvcTest - requires investigation") |
| 109 | + @Test |
| 110 | + void whenGettingStatementsWithInvalidMoreTokenThenStatusIsBadRequest() throws Exception { |
| 111 | + |
| 112 | + // Given Invalid More Token |
| 113 | + when(statementService.getStatementsMore("invalid")) |
| 114 | + .thenThrow(new IllegalArgumentException("Invalid token")); |
| 115 | + |
| 116 | + // When Getting Statements With Invalid More Token |
| 117 | + mvc.perform(get("/xapi/statements?more=invalid")) |
| 118 | + |
| 119 | + // Then Status Is Bad Request |
| 120 | + .andExpect(status().isBadRequest()); |
| 121 | + } |
123 | 122 |
|
124 | 123 | @Test |
125 | 124 | void whenGettingMultipleStatementsWithNegativeTimezoneOffsetThenStatusIsBadRequest() |
|
0 commit comments