1 package net.pterodactylus.sone.template
3 import net.pterodactylus.sone.data.Album
4 import net.pterodactylus.sone.data.Image
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.sone.test.whenever
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
9 import org.hamcrest.Matchers.nullValue
10 import org.junit.Before
14 * Unit test for [ImageAccessor].
16 class ImageAccessorTest {
18 private val accessor = ImageAccessor()
19 private val album = mock<Album>()
20 private val images = listOf(mock<Image>(), mock())
24 whenever(album.images).thenReturn(images)
26 whenever(it.album).thenReturn(album)
31 fun `accessor returns next image for first image`() {
32 assertThat(accessor.get(null, images[0], "next"), equalTo<Any>(images[1]))
36 fun `accessor returns null for next image of second image`() {
37 assertThat(accessor.get(null, images[1], "next"), nullValue())
41 fun `accessor returns previous image for second image`() {
42 assertThat(accessor.get(null, images[1], "previous"), equalTo<Any>(images[0]))
46 fun `accessor returns null for previous image of first image`() {
47 assertThat(accessor.get(null, images[0], "previous"), nullValue())
51 fun `accessor uses reflection accessor for all other members`() {
52 assertThat(accessor.get(null, images[0], "hashCode"), equalTo<Any>(images[0].hashCode()))