From d646f960cadc7de7f13f6c23798575b8f0e6634a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 14 Jun 2017 08:11:15 +0200 Subject: [PATCH] Replace SMBC filter test with Kotlin version --- ...urdayMorningBreakfastCerealComicFilterTest.java | 54 ---------------------- ...aturdayMorningBreakfastCerealComicFilterTest.kt | 43 +++++++++++++++++ 2 files changed, 43 insertions(+), 54 deletions(-) delete mode 100644 src/test/java/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.java create mode 100644 src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.kt 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 index c6ed1ab..0000000 --- a/src/test/java/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.java +++ /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 David ‘Bombe’ Roden - */ -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 index 0000000..45e97bf --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/SaturdayMorningBreakfastCerealComicFilterTest.kt @@ -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("")) + } + } + +} -- 2.7.4