jeudi 3 septembre 2015

Wrong response status in spring boot with annotated exception

In Spring Boot 1.2.5, I annotated an exception as follow:

@ResponseStatus(value=HttpStatus.NOT_FOUND)
public class SomethingNotFoundException extends RuntimeException{}

Then in the test

@Mock
AService aService;

@Test
    public void testHandleCsvFileUpload_BadCSVException() throws Exception {
        final Long itemId=1L;
        doThrow(new SomethingNotFoundException("No Item")).when(aService).verifySomething(itemId);

        mockMvc.perform(get("/rest/service"))
                .andExpect(status().isNotFound())

          verify(aService, times(1)).existsOrThrow(itemId);
    }

I don't understand why instead of NotFound, NotAcceptable is returned:

java.lang.AssertionError: Expected status code <404> doesn't match actual status code <406>.

Clearly, if I expect status code 406 the test pass, and the method that has to throw is verified. Any idea?

Aucun commentaire:

Enregistrer un commentaire