我正在嘗試測驗回應中的欄位是否不等于某個值,例如:
@Test
void whenAnAuth0ExceptionIsThrown_itShouldNotLeakInformation() throws Exception {
String description = "Resource not found.";
Auth0Exception auth0Exception = new Auth0Exception(description);
when(usersService.getRoles()).thenThrow(new UnrecoverableAuthException("api exception", auth0Exception));
mockMvc.perform(get("/v1/users/roles").with(csrf()))
.andExpect(status().isInternalServerError())
.andExpect(jsonPath("$.errorMessage").value(AdditionalMatchers.not(description)));
verify(usersService).getRoles();
}
但是當我嘗試這個時,我收到以下錯誤:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
No matchers found for additional matcher Not(?)
我發現的一種解決方法是使用andReturn()然后測驗MvcResult.
uj5u.com熱心網友回復:
你很近。
import static org.hamcrest.Matchers.not;
...
.andExpect(jsonPath("$.errorMessage").value(not(description)));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/528236.html
