lundi 18 mai 2020

Expect an exception with Serenity BDD

Him I'm using Serenity BDD 2.2.7 integrated with Spring Boot to write integration tests and I want to expect an exception.

I have the following test:

@Step("getting ids(parent: {0})")
    public List<Long> getIds(long parent){
        ResponseEntity<List<Long>> result = restTemplate
                .exchange(httpUtils.getUrl(parent),
                        HttpMethod.GET, new HttpEntity<>(httpUtils.getHeader(parent)),
                        new ParameterizedTypeReference<List<Long>>() {
                        });

        return httpUtils.getResult(result);
    }

The restTemplate is Spring's org.springframework.web.client.RestTemplate

Then I want to do something like this:

@Test(expected = HttpClientErrorException.NotFound.class)
public void test() {
    steps.getIds(1L);
}

but instead, I get java.lang.Exception: Unexpected exception, expected<org.springframework.web.client.HttpClientErrorException$NotFound> but was<net.serenitybdd.core.exceptions.UnrecognisedException> and the test fails while the cause of the UnrecognisedException IS HttpClientErrorException$NotFound

How can I solve it?

Aucun commentaire:

Enregistrer un commentaire