From 952da2e6fdd9c4bf9c1944257c5ca921f64dde2a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 26 Aug 2015 21:34:33 +0200 Subject: [PATCH] =?utf8?q?Add=20test=20for=20=E2=80=9CGirl=20Genius,?= =?utf8?q?=E2=80=9D=20fix=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../filters/comics/GirlGeniusComicFilter.java | 20 +-- .../filters/comics/GirlGeniusComicFilterTest.java | 41 +++++ .../rhynodge/filters/comics/girl-genius.html | 173 +++++++++++++++++++++ 3 files changed, 222 insertions(+), 12 deletions(-) create mode 100644 src/test/java/net/pterodactylus/rhynodge/filters/comics/GirlGeniusComicFilterTest.java create mode 100644 src/test/resources/net/pterodactylus/rhynodge/filters/comics/girl-genius.html diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/comics/GirlGeniusComicFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/comics/GirlGeniusComicFilter.java index 1bda719..d2ed5aa 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/comics/GirlGeniusComicFilter.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/comics/GirlGeniusComicFilter.java @@ -17,16 +17,17 @@ package net.pterodactylus.rhynodge.filters.comics; +import static com.google.common.base.Optional.absent; +import static com.google.common.base.Optional.of; + import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import net.pterodactylus.rhynodge.filters.ComicSiteFilter; -import com.google.common.base.Function; import com.google.common.base.Optional; -import com.google.common.collect.FluentIterable; import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; import org.jsoup.select.Elements; /** @@ -38,23 +39,18 @@ public class GirlGeniusComicFilter extends ComicSiteFilter { @Override protected Optional extractTitle(Document document) { - return Optional.of(""); + return extractImageUrls(document).isEmpty() ? absent() : of(""); } @Override protected List extractImageUrls(Document document) { - Elements imageElements = document.select("#MainTable img[alt=Comic]"); - return imageElements.hasAttr("src") ? FluentIterable.from(imageElements).transform(new Function() { - - @Override - public String apply(Element imageElement) { - return imageElement.attr("src"); - } - }).toList() : Collections.emptyList(); + Elements imageElements = document.select("#comicbody img[alt=Comic]"); + return imageElements.stream().filter(e -> e.hasAttr("src")).map(e -> e.attr("src")).collect(Collectors.toList()); } @Override protected List extractImageComments(Document document) { return Collections.emptyList(); } + } diff --git a/src/test/java/net/pterodactylus/rhynodge/filters/comics/GirlGeniusComicFilterTest.java b/src/test/java/net/pterodactylus/rhynodge/filters/comics/GirlGeniusComicFilterTest.java new file mode 100644 index 0000000..a45f075 --- /dev/null +++ b/src/test/java/net/pterodactylus/rhynodge/filters/comics/GirlGeniusComicFilterTest.java @@ -0,0 +1,41 @@ +package net.pterodactylus.rhynodge.filters.comics; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; + +import java.io.IOException; + +import net.pterodactylus.rhynodge.Filter; +import net.pterodactylus.rhynodge.filters.ResourceLoader; +import net.pterodactylus.rhynodge.states.ComicState; +import net.pterodactylus.rhynodge.states.HtmlState; + +import org.jsoup.nodes.Document; +import org.junit.Test; + +/** + * Unit test for {@link GirlGeniusComicFilterTest}. + * + * @author David Roden + */ +public class GirlGeniusComicFilterTest { + + private final Filter filter = new GirlGeniusComicFilter(); + private final HtmlState htmlState; + + public GirlGeniusComicFilterTest() throws IOException { + Document document = ResourceLoader.loadDocument(GirlGeniusComicFilter.class, "girl-genius.html", "http://www.girlgeniusonline.com/comic.php"); + htmlState = new HtmlState("http://www.girlgeniusonline.com/comic.php", document); + } + + @Test + public void comicCanBeParsed() { + ComicState comicState = (ComicState) filter.filter(htmlState); + assertThat(comicState.comics(), contains( + ComicMatchers.isComic("", contains( + ComicMatchers.isStrip("http://www.girlgeniusonline.com/ggmain/strips/ggmain20150824.jpg", "") + )) + )); + } + +} diff --git a/src/test/resources/net/pterodactylus/rhynodge/filters/comics/girl-genius.html b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/girl-genius.html new file mode 100644 index 0000000..f0cbc4a --- /dev/null +++ b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/girl-genius.html @@ -0,0 +1,173 @@ + + + + + + Girl Genius + + + + + + +
+
+
+
+
Monday, August 24, 2015
|
Save Bookmark
|
Load Bookmark
+
+ +
+ Comic
+
+
Monday, August 24, 2015
|
Save Bookmark
|
Load Bookmark
+
+
+
+
+ + + +
+
+ + +
+
+
+ +
+ + + + + + + +
+ + +
+
+ + +
+ +
+ + +
Search Girl Genius: + +
Powered by OhNoRobot.com
+ +
+
+ +
+
+
+
+
+
+
+
+ Girl Genius is written by Professors Phil & Kaja Foglio of TPU, with drawings by Prof. P. Foglio. + Volume One was inked by Brian Snoddy. Volumes Two and Three were colored by Mark McNabb. Volume Four was colored by Laurie E. Smith. Cheyenne Wright is our current colorist. His work begins with Volume Five.

+ + Girl Genius is a registered trademark of Studio Foglio, LLC. Agatha Heterodyne, Transylvania Polygnostic and all Girl Genius art, characters, design elements and logos™ & ©2000-2015 Studio Foglio, LLC., All rights reserved. Airship Entertainment™ is an imprint of Studio Foglio LLC, and publishes Girl Genius Graphic Novels on a yearly basis. Look for them in your favorite bookstore! +

+ AutoKeen Lite programmed by Darren Bleuel, as a service of Keenspot Comics. + Special thanks to RB "Sparks" who took it apart and made it work.

+
+
+
+
+
+ + -- 2.7.4