Aug 16, 2024
Capture API Response
print method can be used temporarily to check response body.name and type of returned data.Implement Expect Statements
mockMvcResultMatchers.jsonPath to assert values in the response.expect(mockMvcResultMatchers.jsonPath("$.name").value(pokemonDto.getName()))
name and type match expected values.Testing the Whole Response
when(pokemonService.getAllPokemon(pageSize, pageNumber)).thenReturn(responseDto);
PokemonResponseDTO response = PokemonResponseDTO.builder().pageSize(10).last(true).pageNumber(1).content(new ArrayList<>(pokemonDtos)).build();
mockMvc.perform(get(...)) to simulate the GET request.pageNumber and pageSize) and content type.
application/json.