🎨 Replace Business Cat filter and test with Kotlin versions
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Sep 2020 16:37:10 +0000 (18:37 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Sep 2020 16:37:10 +0000 (18:37 +0200)
src/main/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.java [deleted file]
src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.kt [new file with mode: 0644]
src/test/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.java [deleted file]
src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.kt [new file with mode: 0644]

diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.java
deleted file mode 100644 (file)
index 397c261..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-package net.pterodactylus.rhynodge.filters.comics;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import net.pterodactylus.rhynodge.filters.ComicSiteFilter;
-
-import com.google.common.base.Optional;
-import org.jsoup.nodes.Document;
-
-/**
- * {@link ComicSiteFilter} implementation that can parse Business Cat comics.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
- */
-public class BusinessCatComicFilter extends ComicSiteFilter {
-
-       @Override
-       protected Optional<String> extractTitle(Document document) {
-               String title = document.select(".comic-title h2").text();
-               return title.isEmpty() ? Optional.<String>absent() : Optional.of(title);
-       }
-
-       @Override
-       protected List<String> extractImageUrls(Document document) {
-               return Arrays.asList(document.select(".comic-image img").attr("src"));
-       }
-
-       @Override
-       protected List<String> extractImageComments(Document document) {
-               return Collections.emptyList();
-       }
-
-}
diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.kt b/src/main/kotlin/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilter.kt
new file mode 100644 (file)
index 0000000..54a94c5
--- /dev/null
@@ -0,0 +1,18 @@
+package net.pterodactylus.rhynodge.filters.comics
+
+import com.google.common.base.Optional
+import net.pterodactylus.rhynodge.filters.ComicSiteFilter
+import net.pterodactylus.rhynodge.utils.asOptional
+import org.jsoup.nodes.Document
+
+class BusinessCatComicFilter : ComicSiteFilter() {
+
+       override fun extractTitle(document: Document): Optional<String> =
+                       document.select(".comic-title h2").text().asOptional()
+
+       override fun extractImageUrls(document: Document): List<String> =
+                       listOf(document.select(".comic-image img").attr("src"))
+
+       override fun extractImageComments(document: Document): List<String> = emptyList()
+
+}
diff --git a/src/test/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.java b/src/test/java/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.java
deleted file mode 100644 (file)
index c61957a..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-package net.pterodactylus.rhynodge.filters.comics;
-
-import java.io.IOException;
-
-import net.pterodactylus.rhynodge.filters.ResourceLoader;
-
-import com.google.common.base.Optional;
-import org.hamcrest.MatcherAssert;
-import org.hamcrest.Matchers;
-import org.jsoup.nodes.Document;
-import org.junit.Test;
-
-/**
- * Unit test for {@link BusinessCatComicFilter}.
- */
-public class BusinessCatComicFilterTest {
-
-       private final BusinessCatComicFilter filter = new BusinessCatComicFilter();
-       private final Document document;
-
-       public BusinessCatComicFilterTest() throws IOException {
-               document = ResourceLoader.loadDocument(getClass(), "business-cat.html", "https://www.businesscatcomic.com/");
-       }
-
-       @Test
-       public void imageTitleCanBeExtracted() {
-               MatcherAssert.assertThat(filter.extractTitle(document), Matchers.is(Optional.of("Full Circle")));
-       }
-
-       @Test
-       public void imageUrlsCanBeExtracted() {
-               MatcherAssert.assertThat(filter.extractImageUrls(document), Matchers.contains("https://www.businesscatcomic.com/wp-content/uploads/2019/11/2018-09-07-Full-Circle.png"));
-       }
-
-       @Test
-       public void imageCommentsCanBeExtracted() {
-               MatcherAssert.assertThat(filter.extractImageComments(document), Matchers.empty());
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/BusinessCatComicFilterTest.kt
new file mode 100644 (file)
index 0000000..df7bd8f
--- /dev/null
@@ -0,0 +1,28 @@
+package net.pterodactylus.rhynodge.filters.comics
+
+import net.pterodactylus.rhynodge.filters.ResourceLoader
+import net.pterodactylus.rhynodge.states.ComicState
+import net.pterodactylus.rhynodge.states.HtmlState
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.contains
+import org.junit.Test
+
+/**
+ * Unit test for [BusinessCatComicFilter].
+ */
+class BusinessCatComicFilterTest {
+
+       @Test
+       fun `comic is extracted correctly`() {
+               val comicState = filter.filter(htmlState) as ComicState
+               assertThat(comicState.comics(), contains(
+                               ComicState.Comic("Full Circle").add(ComicState.Strip("https://www.businesscatcomic.com/wp-content/uploads/2019/11/2018-09-07-Full-Circle.png", ""))
+               ))
+       }
+
+       private val filter = BusinessCatComicFilter()
+       private val htmlState: HtmlState = ResourceLoader
+                       .loadDocument(javaClass, "business-cat.html", "https://www.businesscatcomic.com/")
+                       .let { HtmlState("https://www.businesscatcomic.com/", it) }
+
+}