+++ /dev/null
-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();
- }
-
-}
--- /dev/null
+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()
+
+}
+++ /dev/null
-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());
- }
-
-}
--- /dev/null
+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) }
+
+}