Replace SMBC filter test with Kotlin version
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 14 Jun 2017 06:11:15 +0000 (08:11 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 14 Jun 2017 06:11:15 +0000 (08:11 +0200)
src/test/java/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.java [deleted file]
src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.java b/src/test/java/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.java
deleted file mode 100644 (file)
index c6ed1ab..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-package net.pterodactylus.rhynodge.filters.comics;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-
-import java.io.IOException;
-
-import net.pterodactylus.rhynodge.Filter;
-import net.pterodactylus.rhynodge.State;
-import net.pterodactylus.rhynodge.filters.ResourceLoader;
-import net.pterodactylus.rhynodge.states.ComicState;
-import net.pterodactylus.rhynodge.states.ComicState.Comic;
-import net.pterodactylus.rhynodge.states.HtmlState;
-
-import org.hamcrest.Matchers;
-import org.jsoup.nodes.Document;
-import org.junit.Test;
-
-/**
- * Unit test for {@link SaturdayMorningBreakfastCerealComicFilter}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class SaturdayMorningBreakfastCerealComicFilterTest {
-
-       private final Filter smbcFilter = new SaturdayMorningBreakfastCerealComicFilter();
-       private final HtmlState htmlState;
-
-       public SaturdayMorningBreakfastCerealComicFilterTest() throws IOException {
-               Document document = ResourceLoader.loadDocument(SinfestComicFilter.class, "saturday-morning-breakfast-cereal.html", "http://www.smbc-comics.com/");
-               htmlState = new HtmlState("http://www.smbc-comics.com/", document);
-       }
-
-       @Test
-       public void htmlCanBeParsed() {
-               State state = smbcFilter.filter(htmlState);
-               assertThat(state, Matchers.instanceOf(ComicState.class));
-       }
-
-       @Test
-       public void comicIsParsedCorrectly() {
-               ComicState comicState = (ComicState) smbcFilter.filter(htmlState);
-               assertThat(comicState.comics(), hasSize(1));
-               Comic comic = comicState.comics().get(0);
-               assertThat(comic.title(), is(""));
-               assertThat(comic.strips(), hasSize(2));
-               assertThat(comic.strips().get(0).imageUrl(), is("http://www.smbc-comics.com/comics/1496144390-soonish6%20(1).png"));
-               assertThat(comic.strips().get(0).comment(), is("It's not an old man rant if you put it in the mouths of children!"));
-               assertThat(comic.strips().get(1).imageUrl(), is("http://smbc-comics.com/comics/1496144435-soonish6after.png"));
-               assertThat(comic.strips().get(1).comment(), is(""));
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.kt
new file mode 100644 (file)
index 0000000..45e97bf
--- /dev/null
@@ -0,0 +1,43 @@
+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.*
+import org.junit.Test
+
+/**
+ * Unit test for [SaturdayMorningBreakfastCerealComicFilter].
+ */
+class SaturdayMorningBreakfastCerealComicFilterTest {
+
+    private val smbcFilter = SaturdayMorningBreakfastCerealComicFilter()
+    private val htmlState = ResourceLoader.loadDocument(SinfestComicFilter::class.java, "saturday-morning-breakfast-cereal.html", "http://www.smbc-comics.com/").let {
+        HtmlState("http://www.smbc-comics.com/", it)
+    }
+
+    @Test
+    fun htmlCanBeParsed() {
+        val state = smbcFilter.filter(htmlState)
+        assertThat(state, instanceOf(ComicState::class.java))
+    }
+
+    @Test
+    fun comicIsParsedCorrectly() {
+        val comicState = smbcFilter.filter(htmlState) as ComicState
+        assertThat(comicState.comics(), hasSize(1))
+        val comic = comicState.comics().first()
+        assertThat(comic.title(), equalTo(""))
+        assertThat(comic.strips(), hasSize(2))
+        comic.strips().first().also { firstImage ->
+            assertThat(firstImage.imageUrl(), equalTo("http://www.smbc-comics.com/comics/1496144390-soonish6%20(1).png"))
+            assertThat(firstImage.comment(), equalTo("It's not an old man rant if you put it in the mouths of children!"))
+        }
+        comic.strips()[1].also { secondImage ->
+            assertThat(secondImage.imageUrl(), equalTo("http://smbc-comics.com/comics/1496144435-soonish6after.png"))
+            assertThat(secondImage.comment(), equalTo(""))
+        }
+    }
+
+}