8ad16b05186aa896224540f0e3e14ee7ca1ef61f
[rhynodge.git] / src / test / java / net / pterodactylus / rhynodge / filters / comics / AbstruseGooseComicFilterTest.java
1 /*
2  * rhynodge - AbstruseGooseComicFilterTest.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.rhynodge.filters.comics;
19
20 import static com.google.common.base.Optional.of;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.hamcrest.Matchers.contains;
23 import static org.hamcrest.Matchers.is;
24
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.List;
28
29 import com.google.common.base.Optional;
30 import org.jsoup.Jsoup;
31 import org.jsoup.nodes.Document;
32 import org.junit.Test;
33
34 /**
35  * Unit test for {@link AbstruseGooseComicFilter}.
36  *
37  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
38  */
39 public class AbstruseGooseComicFilterTest {
40
41         private final AbstruseGooseComicFilter abstruseGooseComicFilter = new AbstruseGooseComicFilter();
42         private final Document document;
43
44         public AbstruseGooseComicFilterTest() throws IOException {
45                 document = loadDocument("/comics/abstrusegoose.html", "http://abstrusegoose.com/");
46         }
47
48         private Document loadDocument(String resourceName, String baseUri) throws IOException {
49                 InputStream inputStream = getClass().getResourceAsStream(resourceName);
50                 Document document = Jsoup.parse(inputStream, "UTF-8", baseUri);
51                 return document;
52         }
53
54         @Test
55         public void extractsComicTitleCorrectly() {
56                 Optional<String> title = abstruseGooseComicFilter.extractTitle(document);
57                 assertThat(title, is(of("Bizarro")));
58         }
59
60         @Test
61         public void extractComicImagesCorrectly() {
62                 List<String> images = abstruseGooseComicFilter.extractImageUrls(document);
63                 assertThat(images, contains("http://abstrusegoose.com/strips/bizero.png"));
64         }
65
66         @Test
67         public void extractImageCommentsCorrectly() {
68                 List<String> comments = abstruseGooseComicFilter.extractImageComments(document);
69                 assertThat(comments, contains("In the additive group of the integers, bizarro zero is... well... zero."));
70         }
71
72 }