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