From: David ‘Bombe’ Roden Date: Wed, 26 Aug 2015 19:40:56 +0000 (+0200) Subject: Fix parsing of “Cyanide & Happiness.” X-Git-Tag: v2~153 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=710c3666bb0cc2a3200aac939659a56ed985a112;p=rhynodge.git Fix parsing of “Cyanide & Happiness.” --- diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/comics/CyanideAndHappinessComicFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/comics/CyanideAndHappinessComicFilter.java index 8cceb5c..f8d116f 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/comics/CyanideAndHappinessComicFilter.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/comics/CyanideAndHappinessComicFilter.java @@ -17,6 +17,9 @@ package net.pterodactylus.rhynodge.filters.comics; +import static com.google.common.base.Optional.absent; +import static com.google.common.base.Optional.of; + import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -42,7 +45,7 @@ public class CyanideAndHappinessComicFilter extends ComicSiteFilter { @Override protected Optional extractTitle(Document document) { - return Optional.absent(); + return extractImageUrls(document).isEmpty() ? absent() : of(""); } @Override diff --git a/src/test/java/net/pterodactylus/rhynodge/filters/comics/CyanideAndHappinessComicFilterTest.java b/src/test/java/net/pterodactylus/rhynodge/filters/comics/CyanideAndHappinessComicFilterTest.java index ea435d1..f4ddcfd 100644 --- a/src/test/java/net/pterodactylus/rhynodge/filters/comics/CyanideAndHappinessComicFilterTest.java +++ b/src/test/java/net/pterodactylus/rhynodge/filters/comics/CyanideAndHappinessComicFilterTest.java @@ -1,12 +1,14 @@ 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.filters.ResourceLoader; +import net.pterodactylus.rhynodge.states.ComicState; +import net.pterodactylus.rhynodge.states.HtmlState; -import com.google.common.base.Optional; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; import org.jsoup.nodes.Document; import org.junit.Test; @@ -19,24 +21,21 @@ public class CyanideAndHappinessComicFilterTest { private final CyanideAndHappinessComicFilter comicSiteFilter = new CyanideAndHappinessComicFilter(); private final Document document; + private final HtmlState htmlState; public CyanideAndHappinessComicFilterTest() throws IOException { document = ResourceLoader.loadDocument(getClass(), "cyanide-and-happiness.html", "http://www.explosm.net/comics/new/"); + htmlState = new HtmlState("http://files.explosm.net/comics/Kris/skeletor.png", document); } @Test - public void filterCanParseComicTitle() { - MatcherAssert.assertThat(comicSiteFilter.extractTitle(document), Matchers.is(Optional.absent())); - } - - @Test - public void filterCanExtractImageUrls() { - MatcherAssert.assertThat(comicSiteFilter.extractImageUrls(document), Matchers.contains("http://files.explosm.net/comics/Dave/moneyhappiness.png")); - } - - @Test - public void filterExtractNoImageComments() { - MatcherAssert.assertThat(comicSiteFilter.extractImageComments(document), Matchers.empty()); + public void comicCanBeParsed() { + ComicState comicState = (ComicState) comicSiteFilter.filter(htmlState); + assertThat(comicState.comics(), contains( + ComicMatchers.isComic("", contains( + ComicMatchers.isStrip("http://files.explosm.net/comics/Kris/skeletor.png", "") + )) + )); } } diff --git a/src/test/resources/net/pterodactylus/rhynodge/filters/comics/cyanide-and-happiness.html b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/cyanide-and-happiness.html index dee38e2..c8e9368 100644 --- a/src/test/resources/net/pterodactylus/rhynodge/filters/comics/cyanide-and-happiness.html +++ b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/cyanide-and-happiness.html @@ -1,480 +1,479 @@ + -Explosm.net - Home of Cyanide and Happiness - - - - - - - - - - - - - - - - + Cyanide & Happiness (Explosm.net) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-
-
-
-
- -
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
-
-
-
-
-Register  |  Sign In -
-
- -
- -
-
-
-
- -
- -
- -
- +
+ -
-
-
-
-
- -
- -
-
- -
- -
- -
-
-
-
-
-
-
-
-
-
-
-
-
-

More from Explosm

-
-
-

Loading...

-
-
-
-  -
-

Sign in to post a comment

-
-

Loading...

-
-
-
-
-
-
-

Advertisement

-
- - - -
-
-
-
-
-
-
-

Did you know by creating an account you can favorite comics and shorts, automatically bookmark the last one you saw, and more? Learn more about it here!

-
- -
-
- - - - - -
+
+
+
+ + + +
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+ +
+
+

+ +

+ + +



+
+
+
+

More from Explosm

+
+
+

Loading...

+
+
+
+   +
+

Sign in to post a comment

+
+

Loading...

+
+
+
+
+
+
+

Advertisement

+
+ +
+
+
+ +
+
+
+
+
+
+
+
+
+

Did you know by creating an account you can favorite comics and shorts, automatically bookmark the last one you saw, and more? Learn more about it here!

+
+
+ Sign up! +
+
+
+ + + + + +
-
-
-
-

Log in or Register

+
+
+
+

Log in or Register

+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ +
+
+
+
+
+
+
+
+ Don't have an account? Join the cool kids here! +
+
+
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
- - -
-
-
-
- - -
-
-
-
- -
-
- -
-
-
-
-
-
-
-
-Don't have an account? Join the cool kids here! -
-
-
-
-
- -
- -
-
- - - - - - + + + + + + + - - + + + + + + +
+ + + +
+ +
+ + +