🔀 Merge branch 'release/v82'
[Sone.git] / pterodactylus / sone / template / ImageAccessorTest.kt
1 package net.pterodactylus.sone.template
2
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
11 import org.junit.Test
12
13 /**
14  * Unit test for [ImageAccessor].
15  */
16 class ImageAccessorTest {
17
18         private val accessor = ImageAccessor()
19         private val album = mock<Album>()
20         private val images = listOf(mock<Image>(), mock())
21
22         @Before
23         fun setupImages() {
24                 whenever(album.images).thenReturn(images)
25                 images.forEach {
26                         whenever(it.album).thenReturn(album)
27                 }
28         }
29
30         @Test
31         fun `accessor returns next image for first image`() {
32                 assertThat(accessor.get(null, images[0], "next"), equalTo<Any>(images[1]))
33         }
34
35         @Test
36         fun `accessor returns null for next image of second image`() {
37                 assertThat(accessor.get(null, images[1], "next"), nullValue())
38         }
39
40         @Test
41         fun `accessor returns previous image for second image`() {
42                 assertThat(accessor.get(null, images[1], "previous"), equalTo<Any>(images[0]))
43         }
44
45         @Test
46         fun `accessor returns null for previous image of first image`() {
47                 assertThat(accessor.get(null, images[0], "previous"), nullValue())
48         }
49
50         @Test
51         fun `accessor uses reflection accessor for all other members`() {
52                 assertThat(accessor.get(null, images[0], "hashCode"), equalTo<Any>(images[0].hashCode()))
53         }
54
55 }