From 710c3666bb0cc2a3200aac939659a56ed985a112 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:40:56 +0200 Subject: [PATCH] =?utf8?q?Fix=20parsing=20of=20=E2=80=9CCyanide=20&=20Happ?= =?utf8?q?iness.=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../comics/CyanideAndHappinessComicFilter.java | 5 +- .../comics/CyanideAndHappinessComicFilterTest.java | 29 +- .../filters/comics/cyanide-and-happiness.html | 927 ++++++++++----------- 3 files changed, 481 insertions(+), 480 deletions(-) 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! -
-
-
-
-
- -
- -
-
- - - - - - + + + + + + + - - + + + + + + +
+ + + +
+ +
+ + + -- 2.7.4