I recently read and used some examples as seen in the GitHub Repo linked below, which is for extending the basic Spring Boot error objects. I am attempting to write some tests for the ApiError.java class, and in particular #addValidationErrors
The basic issue is that I've not found a way to get the chaining of the methods to return values to work. My test at this point looks something like this...
@Test
public void addValidationErrors() {
ApiError apiError = new ApiError(HttpStatus.OK);
ConstraintViolation mockViolation = Mockito.mock(ConstraintViolation.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(mockViolation.getRootBeanClass().getSimpleName()).thenReturn("MyBeanName");
...
At this point the test dies with a NullPointerException on the line which invokes the Mockito.when method. I've tried different runner classes (Mockito, JUnit4 and even PowerMock) along with various annotation combinations such as @PrepareForTest and declaring the mockViolation outside the test under a @Mock.
Aucun commentaire:
Enregistrer un commentaire