45e97bf9800afa54d42142595fa0849ce0f4182f
[rhynodge.git] /
1 package net.pterodactylus.rhynodge.filters.comics
2
3 import net.pterodactylus.rhynodge.filters.ResourceLoader
4 import net.pterodactylus.rhynodge.states.ComicState
5 import net.pterodactylus.rhynodge.states.HtmlState
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.*
8 import org.junit.Test
9
10 /**
11  * Unit test for [SaturdayMorningBreakfastCerealComicFilter].
12  */
13 class SaturdayMorningBreakfastCerealComicFilterTest {
14
15     private val smbcFilter = SaturdayMorningBreakfastCerealComicFilter()
16     private val htmlState = ResourceLoader.loadDocument(SinfestComicFilter::class.java, "saturday-morning-breakfast-cereal.html", "http://www.smbc-comics.com/").let {
17         HtmlState("http://www.smbc-comics.com/", it)
18     }
19
20     @Test
21     fun htmlCanBeParsed() {
22         val state = smbcFilter.filter(htmlState)
23         assertThat(state, instanceOf(ComicState::class.java))
24     }
25
26     @Test
27     fun comicIsParsedCorrectly() {
28         val comicState = smbcFilter.filter(htmlState) as ComicState
29         assertThat(comicState.comics(), hasSize(1))
30         val comic = comicState.comics().first()
31         assertThat(comic.title(), equalTo(""))
32         assertThat(comic.strips(), hasSize(2))
33         comic.strips().first().also { firstImage ->
34             assertThat(firstImage.imageUrl(), equalTo("http://www.smbc-comics.com/comics/1496144390-soonish6%20(1).png"))
35             assertThat(firstImage.comment(), equalTo("It's not an old man rant if you put it in the mouths of children!"))
36         }
37         comic.strips()[1].also { secondImage ->
38             assertThat(secondImage.imageUrl(), equalTo("http://smbc-comics.com/comics/1496144435-soonish6after.png"))
39             assertThat(secondImage.comment(), equalTo(""))
40         }
41     }
42
43 }