Added test for when there are multiple pages of images
This commit is contained in:
parent
87b77cf5aa
commit
0b1bb099df
@ -1,5 +1,6 @@
|
||||
package uk.co.neviyn.booru
|
||||
|
||||
import org.hamcrest.Matchers
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.mockito.Mockito
|
||||
@ -48,5 +49,30 @@ internal class ImageControllerTest {
|
||||
.andExpect(MockMvcResultMatchers.view().name("gallery"))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("imagePage", page))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("pageNumber", 1))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.model().attribute(
|
||||
"imagePage",
|
||||
Matchers.hasProperty<Int>("totalPages", Matchers.equalTo(1))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get a gallery page with multiple page of images`() {
|
||||
val images = (1..25).map { Image(id = it.toLong(), filename = "example$it.jpg") }
|
||||
val page = PageImpl(images, PageRequest.of(2, 25), 100)
|
||||
doReturn(page).`when`(imageRepository).findAll(Mockito.any(PageRequest::class.java))
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/gallery?page=2"))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||
.andExpect(MockMvcResultMatchers.view().name("gallery"))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("imagePage", page))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("pageNumber", 2))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.model().attribute(
|
||||
"imagePage",
|
||||
Matchers.hasProperty<Int>("totalPages", Matchers.equalTo(4))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user