Как мы можем assertNotNull response.getBody (); - PullRequest
0 голосов
/ 13 июля 2020

У меня есть логический метод, чтобы проверить, находится ли пользователь в базе данных или нет.

 public boolean verifyUserExists(String userId) {
    if (userId != null) {
        HttpHeaders requestHeader = getRequestHeadersBuilder().build(this);
        ResponseEntity responseEntity = getApiRequestService()
                .doGet(buildURI(userId, applicantsURI), requestHeader, Map.class);
        if (responseEntity.getBody() != null) {
            return true;
        }
    }
    return false;
}

@Test
public void whenUserExists_AndBodyNotNull () {
    HttpHeaders httpHeaders = new HttpHeaders();

    // userId should not be null
    boolean userExists = underTest.verifyUserExists(userId);
    assertTrue(userExists);

    // response.getBody should not be null
    ResponseEntity expected = new ResponseEntity(HttpStatus.NO_CONTENT);
    assertNotNull(expected.getBody());
    when(apiRequestService.doGet(any(URI.class), eq(httpHeaders), eq(Object.class)))
            .thenReturn(expected);

    //should return true

}

Для этого я получаю nullPointerException для response.getBody (); Мне нужно как-то утверждать, что тело не пусто, и вернуть истину.

...