Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface BrandController {
- fun findDTOs(pageable: Pageable): ResponseEntity<Page<SomeDTO>>
- }
- var response: ResponseEntity<*>
- @Test
- fun `test`() {
- `given TestRestTemplate`()
- `when findDTOs`()
- `then check body`()
- }
- protected fun `given not authorization`() {
- restTemplate = TestRestTemplate()
- }
- private fun `when findDTOs`() {
- // RestResponsePage<T> extends PageImpl<T>
- response = restTemplate.getForEntity<RestResponsePage<SomeDTO>>(createUrlWithParams(url, requestPage))
- }
- private fun `then check body`() {
- val body: Page<SomeDTO> = response.body as Page<SomeDTO> // body: "Page 2 of 2 containing java.util.LinkedHashMap instances"
- assertEquals(requestPage.size, body.size) // success
- val content: List<SomeDTO> = body.content as List<SomeDTO> // content: size = 10 body: "Page 2 of 2 containing java.util.LinkedHashMap instances"
- brands.forEachIndexed { index, someDTO: SomeDTO-> //Error
- assertEquals(list[index].name, someDTO.name)
- assertEquals(list[index].id, someDTO.id)
- }
- }
- java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com....SomeDTO
Add Comment
Please, Sign In to add comment