25e4e283b74015b491ef4a51048b950dcfba025f
[rhynodge.git] /
1 package net.pterodactylus.rhynodge.filters.comics;
2
3 import java.io.IOException;
4
5 import net.pterodactylus.rhynodge.Filter;
6 import net.pterodactylus.rhynodge.State;
7 import net.pterodactylus.rhynodge.filters.ResourceLoader;
8 import net.pterodactylus.rhynodge.states.ComicState;
9 import net.pterodactylus.rhynodge.states.ComicState.Comic;
10 import net.pterodactylus.rhynodge.states.HtmlState;
11
12 import org.hamcrest.MatcherAssert;
13 import org.hamcrest.Matchers;
14 import org.jsoup.nodes.Document;
15 import org.junit.Test;
16
17 /**
18  * Unit test for {@link SaturdayMorningBreakfastCerealComicFilter}.
19  *
20  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
21  */
22 public class SaturdayMorningBreakfastCerealComicFilterTest {
23
24         private final Filter smbcFilter = new SaturdayMorningBreakfastCerealComicFilter();
25         private final HtmlState htmlState;
26
27         public SaturdayMorningBreakfastCerealComicFilterTest() throws IOException {
28                 Document document = ResourceLoader.loadDocument(SinfestComicFilter.class, "saturday-morning-breakfast-cereal.html", "http://www.smbc-comics.com/");
29                 htmlState = new HtmlState("http://www.smbc-comics.com/", document);
30         }
31
32         @Test
33         public void htmlCanBeParsed() {
34                 State state = smbcFilter.filter(htmlState);
35                 MatcherAssert.assertThat(state, Matchers.instanceOf(ComicState.class));
36         }
37
38         @Test
39         public void comicIsParsedCorrectly() {
40                 ComicState comicState = (ComicState) smbcFilter.filter(htmlState);
41                 MatcherAssert.assertThat(comicState.comics(), Matchers.hasSize(1));
42                 Comic comic = comicState.comics().get(0);
43                 MatcherAssert.assertThat(comic.title(), Matchers.is(""));
44                 MatcherAssert.assertThat(comic.strips(), Matchers.hasSize(2));
45                 MatcherAssert.assertThat(comic.strips().get(0).imageUrl(), Matchers.is("http://www.smbc-comics.com/comics/1430750631-20150504.png"));
46                 MatcherAssert.assertThat(comic.strips().get(0).comment(), Matchers.is("And they say there's no use for a liberal arts degree!"));
47                 MatcherAssert.assertThat(comic.strips().get(1).imageUrl(), Matchers.is("http://smbc-comics.com/comics/1430750631-20150504after.png"));
48                 MatcherAssert.assertThat(comic.strips().get(1).comment(), Matchers.is(""));
49         }
50
51 }