diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/AddonsTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/AddonsTest.kt index f03a2c2..dbcc6f0 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/AddonsTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/AddonsTest.kt @@ -35,6 +35,7 @@ package net.thauvin.erik.mobibot import assertk.assertThat import assertk.assertions.containsExactly import assertk.assertions.isEqualTo +import assertk.assertions.size import net.thauvin.erik.mobibot.commands.ChannelFeed import net.thauvin.erik.mobibot.commands.Cycle import net.thauvin.erik.mobibot.commands.Die @@ -66,8 +67,8 @@ class AddonsTest { addons.add(War()) addons.add(Dice()) addons.add(Lookup()) - assertThat(addons.modules.size, "modules = 2").isEqualTo(2) - assertThat(addons.names.modules, "module names").containsExactly("Joke", "RockPaperScissors") + assertThat(addons.modules, "modules").size().isEqualTo(2) + assertThat(addons.names.modules, "names.modules").containsExactly("Joke", "RockPaperScissors") // Commands addons.add(View()) @@ -77,11 +78,11 @@ class AddonsTest { addons.add(ChannelFeed("channel")) // no properties, disabled p[Ignore.IGNORE_PROP] = "nick" addons.add(Ignore()) - assertThat(addons.commands.size, "commands = 3").isEqualTo(3) + assertThat(addons.commands, "command").size().isEqualTo(3) - assertThat(addons.names.ops, "ops names").containsExactly("cycle") + assertThat(addons.names.ops, "names.ops").containsExactly("cycle") - assertThat(addons.names.commands, "command names").containsExactly( + assertThat(addons.names.commands, "names.command").containsExactly( "joke", "rock", "paper", diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/FeedReaderTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/FeedReaderTest.kt index d05d9fd..eadcc43 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/FeedReaderTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/FeedReaderTest.kt @@ -33,11 +33,15 @@ package net.thauvin.erik.mobibot import assertk.assertThat import assertk.assertions.contains +import assertk.assertions.index import assertk.assertions.isEqualTo import assertk.assertions.isFailure import assertk.assertions.isInstanceOf +import assertk.assertions.prop +import assertk.assertions.size import com.rometools.rome.io.FeedException import net.thauvin.erik.mobibot.FeedReader.Companion.readFeed +import net.thauvin.erik.mobibot.msg.Message import org.testng.annotations.Test import java.io.IOException import java.net.MalformedURLException @@ -50,15 +54,15 @@ class FeedReaderTest { @Test fun readFeedTest() { var messages = readFeed("https://feeds.thauvin.net/ethauvin") - assertThat(messages.size, "size = 10").isEqualTo(10) - assertThat(messages[1].msg, "feed entry url").contains("erik.thauvin.net") + assertThat(messages, "messages").size().isEqualTo(10) + assertThat(messages, "messages").index(1).prop(Message::msg).contains("erik.thauvin.net") messages = readFeed("https://lorem-rss.herokuapp.com/feed?length=0") - assertThat(messages[0].msg, "nothing to view").contains("nothing") + assertThat(messages, "messages").index(0).prop(Message::msg).contains("nothing") messages = readFeed("https://lorem-rss.herokuapp.com/feed?length=42", 42) - assertThat(messages.size, "messages = 84").isEqualTo(84) - assertThat(messages.last().msg, "example entry url").contains("http://example.com/test/") + assertThat(messages, "messages").size().isEqualTo(84) + assertThat(messages.last(), "messages.last").prop(Message::msg).contains("http://example.com/test/") assertThat { readFeed("blah") }.isFailure().isInstanceOf(MalformedURLException::class.java) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/PinboardTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/PinboardTest.kt index 56f6fd8..3ee0f26 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/PinboardTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/PinboardTest.kt @@ -53,18 +53,18 @@ class PinboardTest : LocalProperties() { pinboard.setApiToken(apiToken) pinboard.addPin(ircServer, entry) - assertTrue(validatePin(apiToken, url = entry.link, entry.title, entry.nick, entry.channel), "validate add") + assertTrue(validatePin(apiToken, url = entry.link, entry.title, entry.nick, entry.channel), "addPin") entry.link = "https://www.example.com/${(5001..9999).random()}" pinboard.updatePin(ircServer, url, entry) - assertTrue(validatePin(apiToken, url = entry.link, ircServer), "validate update") + assertTrue(validatePin(apiToken, url = entry.link, ircServer), "updatePin") entry.title = "Foo Title" pinboard.updatePin(ircServer, entry.link, entry) - assertTrue(validatePin(apiToken, url = entry.link, entry.title), "validate title") + assertTrue(validatePin(apiToken, url = entry.link, entry.title), "updatePin(${entry.title}") pinboard.deletePin(entry) - assertFalse(validatePin(apiToken, url = entry.link), "validate delete") + assertFalse(validatePin(apiToken, url = entry.link), "deletePin") } private fun validatePin(apiToken: String, url: String, vararg matches: String): Boolean { diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/UtilsTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/UtilsTest.kt index 4797369..d6fe27d 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/UtilsTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/UtilsTest.kt @@ -98,8 +98,8 @@ class UtilsTest { @Test fun testBold() { - assertThat(1.bold(), "1.bold()").isEqualTo(Colors.BOLD + "1" + Colors.BOLD) - assertThat(2L.bold(), "1.bold()").isEqualTo(Colors.BOLD + "2" + Colors.BOLD) + assertThat(1.bold(), "bold(1)").isEqualTo(Colors.BOLD + "1" + Colors.BOLD) + assertThat(2L.bold(), "bold(2L)").isEqualTo(Colors.BOLD + "2" + Colors.BOLD) assertThat(ascii.bold(), "ascii.bold()").isEqualTo(Colors.BOLD + ascii + Colors.BOLD) assertThat("test".bold(), "test.bold()").isEqualTo(Colors.BOLD + "test" + Colors.BOLD) } @@ -132,7 +132,7 @@ class UtilsTest { .isEqualTo(Colors.BOLD + ascii + Colors.BOLD) assertThat(null.colorize(Colors.RED), "null.colorize()").isEqualTo("") assertThat("".colorize(Colors.RED), "colorize()").isEqualTo("") - assertThat(ascii.colorize(DEFAULT_COLOR), "none.colorize()").isEqualTo(ascii) + assertThat(ascii.colorize(DEFAULT_COLOR), "ascii.colorize()").isEqualTo(ascii) assertThat(" ".colorize(Colors.NORMAL), "blank.colorize()") .isEqualTo(Colors.NORMAL + " " + Colors.NORMAL) } @@ -165,19 +165,19 @@ class UtilsTest { @Test fun testHelpCmdSyntax() { val bot = "mobibot" - assertThat(helpCmdSyntax("%c $test %n $test", bot, false), "public") + assertThat(helpCmdSyntax("%c $test %n $test", bot, false), "helpCmdSyntax(private)") .isEqualTo("$bot: $test $bot $test") - assertThat(helpCmdSyntax("%c %n $test %c $test %n", bot, true), "public") + assertThat(helpCmdSyntax("%c %n $test %c $test %n", bot, true), "helpCmdSyntax(public)") .isEqualTo("/msg $bot $bot $test /msg $bot $test $bot") } @Test fun testHelpFormat() { - assertThat(helpFormat(test, isBold = true, isIndent = false), "bold") + assertThat(helpFormat(test, isBold = true, isIndent = false), "helpFormat(bold)") .isEqualTo("${Colors.BOLD}$test${Colors.BOLD}") - assertThat(helpFormat(test, isBold = false, isIndent = true), "indent") + assertThat(helpFormat(test, isBold = false, isIndent = true), "helpFormat(indent)") .isEqualTo(test.prependIndent()) - assertThat(helpFormat(test, isBold = true, isIndent = true), "bold-indent") + assertThat(helpFormat(test, isBold = true, isIndent = true), "helpFormat(bold,indent)") .isEqualTo(test.colorize(Colors.BOLD).prependIndent()) } @@ -191,9 +191,9 @@ class UtilsTest { @Test fun testLastOrEmpty() { val two = listOf("1", "2") - assertThat(two.lastOrEmpty(), "two").isEqualTo("2") + assertThat(two.lastOrEmpty(), "lastOrEmpty(1,2)").isEqualTo("2") val one = listOf("1") - assertThat(one.lastOrEmpty(), "one").isEqualTo("") + assertThat(one.lastOrEmpty(), "lastOrEmpty(1)").isEqualTo("") } @Test diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/commands/InfoTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/commands/InfoTest.kt index 04652ea..8230ec4 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/commands/InfoTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/commands/InfoTest.kt @@ -40,14 +40,20 @@ import org.testng.annotations.Test class InfoTest { @Test(groups = ["commands"]) fun testToUptime() { - assertThat(547800300076L.toUptime(), "full").isEqualTo("17 years 2 months 2 weeks 1 day 6 hours 45 minutes") - assertThat(24300000L.toUptime(), "hours minutes").isEqualTo("6 hours 45 minutes") - assertThat(110700000L.toUptime(), "days hours minutes").isEqualTo("1 day 6 hours 45 minutes") - assertThat(1320300000L.toUptime(), "weeks days hours minutes").isEqualTo("2 weeks 1 day 6 hours 45 minutes") - assertThat(2700000L.toUptime(), "45 minutes").isEqualTo("45 minutes") - assertThat(60000L.toUptime(), "1 minute").isEqualTo("1 minute") - assertThat(59000L.toUptime(), "59 seconds").isEqualTo("59 seconds") - assertThat(0L.toUptime(), "0 second").isEqualTo("0 second") + assertThat( + 547800300076L.toUptime(), + "upTime(full)" + ).isEqualTo("17 years 2 months 2 weeks 1 day 6 hours 45 minutes") + assertThat(24300000L.toUptime(), "upTime(hours minutes)").isEqualTo("6 hours 45 minutes") + assertThat(110700000L.toUptime(), "upTime(days hours minutes)").isEqualTo("1 day 6 hours 45 minutes") + assertThat( + 1320300000L.toUptime(), + "upTime(weeks days hours minutes)" + ).isEqualTo("2 weeks 1 day 6 hours 45 minutes") + assertThat(2700000L.toUptime(), "upTime(45 minutes)").isEqualTo("45 minutes") + assertThat(60000L.toUptime(), "upTime(1 minute)").isEqualTo("1 minute") + assertThat(59000L.toUptime(), "upTime(59 seconds)").isEqualTo("59 seconds") + assertThat(0L.toUptime(), "upTime(0 second)").isEqualTo("0 second") } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/commands/RecapTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/commands/RecapTest.kt index 37fbcd1..6894b3d 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/commands/RecapTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/commands/RecapTest.kt @@ -46,7 +46,7 @@ class RecapTest { for (i in 1..20) { Recap.storeRecap("sender$i", "test $i", false) } - assertThat(Recap.recaps, "recap first and last").all { + assertThat(Recap.recaps, "Recap.recaps").all { size().isEqualTo(Recap.MAX_RECAPS) prop(MutableList::first) .matches("[1-2]\\d{3}-[01]\\d-[0-3]\\d [0-2]\\d:[0-6]\\d - sender11: test 11".toRegex()) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/commands/links/LinksMgrTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/commands/links/LinksMgrTest.kt index 47f3621..adcf563 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/commands/links/LinksMgrTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/commands/links/LinksMgrTest.kt @@ -46,14 +46,14 @@ class LinksMgrTest { @Test(groups = ["commands", "links"]) fun fetchTitle() { - assertThat(linksMgr.fetchTitle("https://erik.thauvin.net/"), "Erik").contains("Erik's Weblog") - assertThat(linksMgr.fetchTitle("https://www.google.com/foo"), "Foo").isEqualTo(Constants.NO_TITLE) + assertThat(linksMgr.fetchTitle("https://erik.thauvin.net/"), "fetchTitle(Erik)").contains("Erik's Weblog") + assertThat(linksMgr.fetchTitle("https://www.google.com/foo"), "fetchTitle(Foo)").isEqualTo(Constants.NO_TITLE) } @Test(groups = ["commands", "links"]) fun testMatches() { - assertThat(linksMgr.matches("https://www.example.com/"), "https").isTrue() - assertThat(linksMgr.matches("HTTP://erik.thauvin.net/blog/ Erik's Weblog"), "HTTP").isTrue() + assertThat(linksMgr.matches("https://www.example.com/"), "matches(url)").isTrue() + assertThat(linksMgr.matches("HTTP://erik.thauvin.net/blog/ Erik's Weblog"), "matches(HTTP)").isTrue() } @Test(groups = ["commands", "links"]) @@ -62,11 +62,11 @@ class LinksMgrTest { val tags = mutableListOf() linksMgr.matchTagKeywords("Test title with key2", tags) - assertThat(tags, "key2").contains("key2") + assertThat(tags, "tags").contains("key2") tags.clear() linksMgr.matchTagKeywords("Test key3 title with key1", tags) - assertThat(tags, "key1 & key 3").all { + assertThat(tags, "tags(key1, key3)").all { contains("key1") contains("key3") size().isEqualTo(2) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/commands/seen/SeenTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/commands/seen/SeenTest.kt index 80c8450..a736768 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/commands/seen/SeenTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/commands/seen/SeenTest.kt @@ -33,10 +33,13 @@ package net.thauvin.erik.mobibot.commands.seen import assertk.assertThat +import assertk.assertions.isEmpty import assertk.assertions.isEqualTo import assertk.assertions.isGreaterThan import assertk.assertions.isNotEqualTo -import assertk.assertions.isTrue +import assertk.assertions.isNotNull +import assertk.assertions.key +import assertk.assertions.size import org.testng.annotations.AfterClass import org.testng.annotations.BeforeClass import org.testng.annotations.Test @@ -51,7 +54,7 @@ class SeenTest { @BeforeClass fun saveTest() { seen.add("ErikT") - assertThat(tmpFile.fileSize(), "temporary file is empty").isGreaterThan(0) + assertThat(tmpFile.fileSize(), "tmpFile.size").isGreaterThan(0) } @AfterClass(alwaysRun = true) @@ -62,18 +65,18 @@ class SeenTest { @Test(priority = 1, groups = ["commands"]) fun loadTest() { seen.clear() - assertThat(seen.seenNicks.isEmpty(), "nicknames map is not empty").isTrue() + assertThat(seen.seenNicks, "seenNicks").isEmpty() seen.load() - assertThat(seen.seenNicks.containsKey(nick), "nick is missing").isTrue() + assertThat(seen.seenNicks).key(nick).isNotNull() } @Test(groups = ["commands"]) fun addTest() { val last = seen.seenNicks[nick]?.lastSeen seen.add(nick.lowercase()) - assertThat(seen.seenNicks.size, "nick is duplicated").isEqualTo(1) - assertThat(seen.seenNicks[nick]?.lastSeen, "last seen is not different").isNotEqualTo(last) - assertThat(seen.seenNicks[nick]?.nick, "nick is not lowercase").isEqualTo(nick.lowercase()) + assertThat(seen.seenNicks, "seenNicks").size().isEqualTo(1) + assertThat(seen.seenNicks[nick]?.lastSeen, "seenNicks[$nick].lastSeen").isNotEqualTo(last) + assertThat(seen.seenNicks[nick]?.nick, "seenNicks[$nick].nick").isEqualTo(nick.lowercase()) } @Test(priority = 10, groups = ["commands"]) @@ -81,6 +84,6 @@ class SeenTest { seen.clear() seen.save() seen.load() - assertThat(seen.seenNicks.size, "nicknames are not empty.").isEqualTo(0) + assertThat(seen.seenNicks, "seenNicks").size().isEqualTo(0) } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessageTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessageTest.kt index 1913312..2e4ef6e 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessageTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessageTest.kt @@ -61,13 +61,13 @@ class TellMessageTest { prop(TellMessage::recipient).isEqualTo(recipient) prop(TellMessage::message).isEqualTo(message) } - assertThat(isValidDate(tellMessage.queued), "queued is valid date/time").isTrue() - assertThat(tellMessage.isMatch(sender), "match sender").isTrue() - assertThat(tellMessage.isMatch(recipient), "match recipient").isTrue() - assertThat(tellMessage.isMatch("foo"), "foo is no match").isFalse() + assertThat(isValidDate(tellMessage.queued), "isValidDate()").isTrue() + assertThat(tellMessage.isMatch(sender), "isMatch(sender)").isTrue() + assertThat(tellMessage.isMatch(recipient), "isMatch(recipient)").isTrue() + assertThat(tellMessage.isMatch("foo"), "isMatch(foo)").isFalse() tellMessage.isReceived = false - assertThat(tellMessage.receptionDate, "reception date not set").isEqualTo(LocalDateTime.MIN) + assertThat(tellMessage.receptionDate, "receptionDate").isEqualTo(LocalDateTime.MIN) tellMessage.isReceived = true - assertThat(isValidDate(tellMessage.receptionDate), "received is valid date/time").isTrue() + assertThat(isValidDate(tellMessage.receptionDate), "isValidDate(creationDate)").isTrue() } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessagesMgrTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessagesMgrTest.kt index 24c3bcf..fe83db7 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessagesMgrTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessagesMgrTest.kt @@ -40,6 +40,7 @@ import assertk.assertions.isFalse import assertk.assertions.isGreaterThan import assertk.assertions.isTrue import assertk.assertions.prop +import assertk.assertions.size import org.testng.annotations.AfterClass import org.testng.annotations.BeforeClass import org.testng.annotations.Test @@ -74,9 +75,9 @@ class TellMessagesMgrTest { queued = LocalDateTime.now().minusDays(maxDays) }) val size = testMessages.size - assertThat(TellMessagesMgr.clean(testMessages, maxDays + 2), "maxDays = 12").isFalse() - assertThat(TellMessagesMgr.clean(testMessages, maxDays), "maxDays = 10").isTrue() - assertThat(testMessages.size, "size-- after clean").isEqualTo(size - 1) + assertThat(TellMessagesMgr.clean(testMessages, maxDays + 2), "clean(maxDays=${maxDays + 2})").isFalse() + assertThat(TellMessagesMgr.clean(testMessages, maxDays), "clean(maxDays=$maxDays)").isTrue() + assertThat(testMessages, "testMessages").size().isEqualTo(size - 1) } @Test(groups = ["commands", "tell"]) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtilsTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtilsTest.kt index 06e50d8..0de9d5e 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtilsTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtilsTest.kt @@ -77,8 +77,8 @@ class EntriesUtilsTest { ).isEqualTo("L$i: [Skynx$i] \u0002Mobitopia$i\u0002 ( \u000303https://www.mobitopia.org/$i\u000F )") } - assertThat(links.first().addComment(comment), "add comment").isEqualTo(0) - assertThat(buildLink(0, links.first(), isView = true), "isView = true").contains("[+1]") + assertThat(links.first().addComment(comment), "addComment()").isEqualTo(0) + assertThat(buildLink(0, links.first(), isView = true), "buildLink(isView=true)").contains("[+1]") } @Test(groups = ["entries"]) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/entries/EntryLinkTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/entries/EntryLinkTest.kt index a88c9a5..bef4ba9 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/entries/EntryLinkTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/entries/EntryLinkTest.kt @@ -65,7 +65,7 @@ class EntryLinkTest { entryLink.addComment("c$i", "u$i") i++ } - assertThat(entryLink.comments.size, "getComments().size() == 5").isEqualTo(i) + assertThat(entryLink.comments, "comments").size().isEqualTo(i) i = 0 for (comment in entryLink.comments) { assertThat(comment).all { @@ -83,11 +83,11 @@ class EntryLinkTest { entryLink.addComment("nothing", "nobody") entryLink.setComment(0, "something", "somebody") val comment = entryLink.getComment(0) - assertThat(comment, "get first comment").all { + assertThat(comment, "comment[first]").all { prop(EntryComment::nick).isEqualTo("somebody") prop(EntryComment::comment).isEqualTo("something") } - assertThat(entryLink.deleteComment(comment), "delete comment").isTrue() + assertThat(entryLink.deleteComment(comment), "deleteComment").isTrue() assertThat(entryLink.deleteComment(comment), "comment is already deleted").isFalse() } @@ -96,19 +96,19 @@ class EntryLinkTest { val tag = "test" val tags = listOf(SyndCategoryImpl().apply { name = tag }) val link = EntryLink("link", "title", "nick", "channel", Date(), tags) - assertThat(link.tags.size, "check tag size").isEqualTo(tags.size) - assertThat(link.tags[0].name, "check tag name").isEqualTo(tag) - assertThat(link.pinboardTags, "check pinboard tags").isEqualTo("nick,$tag") + assertThat(link.tags, "tags").size().isEqualTo(tags.size) + assertThat(link.tags[0].name, "tag[0].name").isEqualTo(tag) + assertThat(link.pinboardTags, "pinboardTags").isEqualTo("nick,$tag") } @Test(groups = ["entries"]) fun testMatches() { - assertThat(entryLink.matches("mobitopia"), "match mobitopia").isTrue() - assertThat(entryLink.matches("skynx"), "match nick").isTrue() - assertThat(entryLink.matches("www.mobitopia.org"), "match url").isTrue() - assertThat(entryLink.matches("foo"), "match foo").isFalse() - assertThat(entryLink.matches(""), "match empty").isFalse() - assertThat(entryLink.matches(null), "match null").isFalse() + assertThat(entryLink.matches("mobitopia"), "matches(mobitopia)").isTrue() + assertThat(entryLink.matches("skynx"), "match(nick)").isTrue() + assertThat(entryLink.matches("www.mobitopia.org"), "matches(url)").isTrue() + assertThat(entryLink.matches("foo"), "matches(foo)").isFalse() + assertThat(entryLink.matches(""), "matches(empty)").isFalse() + assertThat(entryLink.matches(null), "matches(null)").isFalse() } @@ -116,19 +116,19 @@ class EntryLinkTest { fun testTags() { val tags: List = entryLink.tags for ((i, tag) in tags.withIndex()) { - assertThat(tag.name, "tag.getName($i)").isEqualTo("tag" + (i + 1)) + assertThat(tag.name, "tag.name($i)").isEqualTo("tag${i + 1}") } - assertThat(entryLink.tags, "size is 5").size().isEqualTo(5) + assertThat(entryLink.tags, "tags").size().isEqualTo(5) entryLink.setTags("-tag5") entryLink.setTags("+mobitopia") entryLink.setTags("tag4") entryLink.setTags("-mobitopia") - assertThat(entryLink.pinboardTags, "getPinboardTags()") + assertThat(entryLink.pinboardTags, "pinboardTags") .isEqualTo(entryLink.nick + ",tag1,tag2,tag3,tag4,mobitopia") val size = entryLink.tags.size entryLink.setTags("") - assertThat(entryLink.tags.size, "empty tag").isEqualTo(size) + assertThat(entryLink.tags, "setTags('')").size().isEqualTo(size) entryLink.setTags(" ") - assertThat(entryLink.tags.size, "blank tag").isEqualTo(size) + assertThat(entryLink.tags, "setTags(' ')").size().isEqualTo(size) } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/entries/FeedMgrTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/entries/FeedMgrTest.kt index 31cfb99..a92f2b1 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/entries/FeedMgrTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/entries/FeedMgrTest.kt @@ -35,17 +35,18 @@ package net.thauvin.erik.mobibot.entries import assertk.all import assertk.assertThat import assertk.assertions.endsWith +import assertk.assertions.exists +import assertk.assertions.index import assertk.assertions.isEqualTo import assertk.assertions.isTrue import assertk.assertions.prop +import assertk.assertions.size import net.thauvin.erik.mobibot.Utils.today import org.testng.annotations.BeforeSuite import org.testng.annotations.Test import java.nio.file.Paths import java.util.Date -import kotlin.io.path.absolutePathString import kotlin.io.path.deleteIfExists -import kotlin.io.path.exists import kotlin.io.path.fileSize import kotlin.io.path.name @@ -64,11 +65,11 @@ class FeedMgrTest { @Test(groups = ["entries"]) fun testFeedMgr() { // Load the feed - assertThat(FeedsMgr.loadFeed(entries), "pubDate").isEqualTo("2021-10-31") + assertThat(FeedsMgr.loadFeed(entries), "loadFeed()").isEqualTo("2021-10-31") - assertThat(entries.links.size, "2 links").isEqualTo(2) + assertThat(entries.links, "entries.links").size().isEqualTo(2) entries.links.forEachIndexed { i, entryLink -> - assertThat(entryLink, "Example $(i + 1)").all { + assertThat(entryLink, "entryLink[${i + 1}]").all { prop(EntryLink::title).isEqualTo("Example ${i + 1}") prop(EntryLink::link).isEqualTo("https://www.example.com/${i + 1}") prop(EntryLink::channel).isEqualTo(channel) @@ -79,19 +80,19 @@ class FeedMgrTest { } with(entries.links.first()) { - assertThat(nick, "first nick").isEqualTo("ErikT") - assertThat(date, "first date").isEqualTo(Date(1635638400000L)) - assertThat(comments.first(), "first comment").all { + assertThat(nick, "nick[first]").isEqualTo("ErikT") + assertThat(date, "date[first]").isEqualTo(Date(1635638400000L)) + assertThat(comments.first(), "comments[first]").all { prop(EntryComment::comment).endsWith("comment 1.") prop(EntryComment::nick).isEqualTo("ErikT") } - assertThat(comments.last(), "last comment").all { + assertThat(comments.last(), "comments[last]").all { prop(EntryComment::comment).endsWith("comment 2.") prop(EntryComment::nick).isEqualTo("Skynx") } } - assertThat(entries.links[1], "second link").all { + assertThat(entries.links, "links").index(1).all { prop(EntryLink::nick).isEqualTo("Skynx") prop(EntryLink::date).isEqualTo(Date(1635638460000L)) } @@ -102,20 +103,20 @@ class FeedMgrTest { // Save the feed FeedsMgr.saveFeed(entries, currentFile.name) - assertThat(currentFile.exists(), "${currentFile.absolutePathString()} exists").isTrue() - assertThat(backlogFile.exists(), "${backlogFile.absolutePathString()} exits").isTrue() + assertThat(currentFile, "currentFile").exists() + assertThat(backlogFile, "backlogFile").exists() - assertThat(currentFile.fileSize(), "files are identical").isEqualTo(backlogFile.fileSize()) + assertThat(currentFile.fileSize(), "currentFile == backlogFile").isEqualTo(backlogFile.fileSize()) // Load the test feed entries.links.clear() FeedsMgr.loadFeed(entries, currentFile.name) entries.links.forEachIndexed { i, entryLink -> - assertThat(entryLink.title, "${currentFile.name} title ${i + 1}").isEqualTo("Example ${i + 1}") + assertThat(entryLink.title, "entryLink.title[${i + 1}]").isEqualTo("Example ${i + 1}") } - assertThat(currentFile.deleteIfExists(), "delete ${currentFile.absolutePathString()}").isTrue() - assertThat(backlogFile.deleteIfExists(), "delete ${backlogFile.absolutePathString()}").isTrue() + assertThat(currentFile.deleteIfExists(), "currentFile.deleteIfExists()").isTrue() + assertThat(backlogFile.deleteIfExists(), "backlogFile.deleteIfExists()").isTrue() } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CalcTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CalcTest.kt index e9c969e..0873e7b 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CalcTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CalcTest.kt @@ -47,7 +47,7 @@ class CalcTest { @Test(groups = ["modules"]) fun testCalculate() { assertThat(calculate("1 + 1"), "calculate(1+1)").isEqualTo("1+1 = ${2.bold()}") - assertThat(calculate("1 -3"), "calculate(1 -3)").isEqualTo("1-3 = ${(-2).bold()}") + assertThat(calculate("1 -3"), "calculate(1-3)").isEqualTo("1-3 = ${(-2).bold()}") assertThat(calculate("pi+π+e+φ"), "calculate(pi+π+e+φ)").isEqualTo("pi+π+e+φ = ${"10.62".bold()}") assertThat { calculate("one + one") }.isFailure().isInstanceOf(UnknownFunctionOrVariableException::class.java) } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CryptoPricesTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CryptoPricesTest.kt index d03c67a..96e6181 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CryptoPricesTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CryptoPricesTest.kt @@ -57,14 +57,14 @@ class CryptoPricesTest { @Throws(ModuleException::class) fun testMarketPrice() { var price = currentPrice(listOf("BTC")) - assertThat(price, "BTC in USD").all { + assertThat(price, "currentPrice(BTC)").all { prop(CryptoPrice::base).isEqualTo("BTC") prop(CryptoPrice::currency).isEqualTo("USD") prop(CryptoPrice::amount).transform { it.signum() }.isGreaterThan(0) } price = currentPrice(listOf("ETH", "EUR")) - assertThat(price, "ETH in EUR").all { + assertThat(price, "currentPrice(ETH, EUR)").all { prop(CryptoPrice::base).isEqualTo("ETH") prop(CryptoPrice::currency).isEqualTo("EUR") prop(CryptoPrice::amount).transform { it.signum() }.isGreaterThan(0) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverterTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverterTest.kt index 4102e6b..66ae5c7 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverterTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CurrencyConverterTest.kt @@ -60,21 +60,21 @@ class CurrencyConverterTest { fun testConvertCurrency() { assertThat( convertCurrency("100 USD to EUR").msg, - "100 USD to EUR is invalid" + "convertCurrency(100 USD to EUR)" ).matches("100 United States Dollar = \\d{2,3}\\.\\d+ Euro".toRegex()) assertThat( convertCurrency("1 USD to BTC").msg, - "1 USD to BTC is invalid" + "convertCurrency(1 USD to BTC)" ).matches("1 United States Dollar = 0\\.\\d+ Bitcoin".toRegex()) assertThat( convertCurrency("100,000.00 GBP to BTC").msg, - "100 USD to EUR is invalid" + "convertCurrency(100,000.00 GBP to BTC)" ).matches("100,000.00 British Pound Sterling = \\d{1,2}\\.\\d+ Bitcoin".toRegex()) - assertThat(convertCurrency("100 USD to USD"), "100 USD to USD is invalid").all { + assertThat(convertCurrency("100 USD to USD"), "convertCurrency(100 USD to USD)").all { prop(Message::msg).contains("You're kidding, right?") isInstanceOf(PublicMessage::class.java) } - assertThat(convertCurrency("100 USD"), "100 USD should be invalid").all { + assertThat(convertCurrency("100 USD"), "convertCurrency(100 USD)").all { prop(Message::msg).contains("Invalid query.") isInstanceOf(ErrorMessage::class.java) } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/DiceTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/DiceTest.kt index 85db410..e391f2a 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/DiceTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/DiceTest.kt @@ -41,14 +41,14 @@ import org.testng.annotations.Test class DiceTest { @Test(groups = ["modules"]) fun testRoll() { - assertThat(Dice.roll(1, 1), "1d1 is invalid").isEqualTo("\u00021\u0002") - assertThat(Dice.roll(2, 1), "2d1 is invalid") + assertThat(Dice.roll(1, 1), "roll(1d1)").isEqualTo("\u00021\u0002") + assertThat(Dice.roll(2, 1), "roll(2d1)") .isEqualTo("\u00021\u0002 + \u00021\u0002 = \u00022\u0002") - assertThat(Dice.roll(5, 1), "5d1 is invalid") + assertThat(Dice.roll(5, 1), "roll(5d1)") .isEqualTo("\u00021\u0002 + \u00021\u0002 + \u00021\u0002 + \u00021\u0002 + \u00021\u0002 = \u00025\u0002") - assertThat(Dice.roll(2, 6), "2d6 is invalid") + assertThat(Dice.roll(2, 6), "roll(2d6)") .matches("\u0002[1-6]\u0002 \\+ \u0002[1-6]\u0002 = \u0002[1-9][0-2]?\u0002".toRegex()) - assertThat(Dice.roll(3, 7), "3d7 is invalid") + assertThat(Dice.roll(3, 7), "roll(3d7)") .matches("\u0002[1-7]\u0002 \\+ \u0002[1-7]\u0002 \\+ \u0002[1-7]\u0002 = \u0002\\d{1,2}\u0002".toRegex()) } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt index 41931c0..6700d2d 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt @@ -36,6 +36,7 @@ import assertk.assertThat import assertk.assertions.contains import assertk.assertions.hasMessage import assertk.assertions.hasNoCause +import assertk.assertions.index import assertk.assertions.isEqualTo import assertk.assertions.isFailure import assertk.assertions.isInstanceOf @@ -56,7 +57,7 @@ class GoogleSearchTest : LocalProperties() { fun testAPIKeys() { assertThat( searchGoogle("", "apikey", "cssKey").first(), - "empty query" + "searchGoogle(empty)" ).isInstanceOf(ErrorMessage::class.java) assertThat { searchGoogle("test", "", "apiKey") }.isFailure() @@ -78,12 +79,14 @@ class GoogleSearchTest : LocalProperties() { val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP) try { - var messages = searchGoogle("mobibot", apiKey, cseKey) - assertThat(messages, "search result should not be empty").isNotEmpty() - assertThat(messages[0].msg, "search query not found").contains("mobibot", true) + var query = "mobibot" + var messages = searchGoogle(query, apiKey, cseKey) + assertThat(messages, "searchGoogle($query)").isNotEmpty() + assertThat(messages, "searchGoogle($query)").index(0).prop(Message::msg).contains(query, true) - messages = searchGoogle("adadflkjl", apiKey, cseKey) - assertThat(messages[0], "not found").all { + query = "adadflkjl" + messages = searchGoogle(query, apiKey, cseKey) + assertThat(messages, "searchGoogle($query)").index(0).all { isInstanceOf(ErrorMessage::class.java) prop(Message::msg).isEqualTo("No results found.") } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/JokeTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/JokeTest.kt index ed921a3..21b455e 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/JokeTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/JokeTest.kt @@ -35,7 +35,10 @@ import assertk.assertThat import assertk.assertions.isGreaterThan import assertk.assertions.isInstanceOf import assertk.assertions.isNotEmpty +import assertk.assertions.prop +import assertk.assertions.size import net.thauvin.erik.mobibot.modules.Joke.Companion.randomJoke +import net.thauvin.erik.mobibot.msg.Message import net.thauvin.erik.mobibot.msg.PublicMessage import org.testng.annotations.Test @@ -47,10 +50,10 @@ class JokeTest { @Throws(ModuleException::class) fun testRandomJoke() { val joke = randomJoke() - assertThat(joke.size, "joke should not be empty").isGreaterThan(0) + assertThat(joke, "randomJoke()").size().isGreaterThan(0) joke.forEach { - assertThat(it, "message should be public").isInstanceOf(PublicMessage::class.java) - assertThat(it.msg, "message should not be empty").isNotEmpty() + assertThat(it, "randomJoke()").isInstanceOf(PublicMessage::class.java) + assertThat(it, "randomJoke()").prop(Message::msg).isNotEmpty() } } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/LookupTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/LookupTest.kt index aa5de8c..734bcb3 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/LookupTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/LookupTest.kt @@ -56,6 +56,6 @@ class LookupTest { @Throws(Exception::class) fun testWhois() { val result = whois("17.178.96.59", Lookup.WHOIS_HOST) - assertThat(result, "whois(17.178.96.59/Apple Inc.").any { it.contains("Apple Inc.") } + assertThat(result, "whois(17.178.96.59").any { it.contains("Apple Inc.") } } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/ModuleExceptionTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/ModuleExceptionTest.kt index 65513d4..948fa80 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/ModuleExceptionTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/ModuleExceptionTest.kt @@ -78,26 +78,32 @@ class ModuleExceptionTest { fun testSanitizeMessage() { val apiKey = "1234567890" var e = ModuleException(debugMessage, message, IOException("URL http://foo.com?apiKey=$apiKey&userID=me")) - assertThat(e.sanitize(apiKey, "", "me").message, "sanitized url is invalid").isNotNull().all { + assertThat( + e.sanitize(apiKey, "", "me").message, "ModuleException(debugMessage, message, IOException(url))" + ).isNotNull().all { contains("xxxxxxxxxx", "userID=xx", "java.io.IOException") doesNotContain(apiKey, "me") } e = ModuleException(debugMessage, message, null) - assertThat(e.sanitize(apiKey), "cause should be null").hasMessage(message) + assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, null)").hasMessage(message) e = ModuleException(debugMessage, message, IOException()) - assertThat(e.sanitize(apiKey), "cause message is invalid").hasMessage(message) + assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, IOException())").hasMessage(message) e = ModuleException(debugMessage, apiKey) - assertThat(e.sanitize(apiKey).message, "message should not contain api key").isNotNull().doesNotContain(apiKey) + assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, apiKey)").isNotNull() + .doesNotContain(apiKey) val msg: String? = null e = ModuleException(debugMessage, msg, IOException(msg)) - assertThat(e.sanitize(apiKey).message, "message should be null").isNull() + assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, msg, IOException(msg))").isNull() e = ModuleException(debugMessage, msg, IOException("foo is $apiKey")) - assertThat(e.sanitize(" ", apiKey, "foo").message, "message should not contain key").isNotNull().all { + assertThat( + e.sanitize(" ", apiKey, "foo").message, + "ModuleException(debugMessage, msg, IOException(foo is $apiKey))" + ).isNotNull().all { doesNotContain(apiKey) endsWith("xxx is xxxxxxxxxx") } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/PingTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/PingTest.kt index d944047..50f7fda 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/PingTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/PingTest.kt @@ -43,13 +43,13 @@ import org.testng.annotations.Test class PingTest { @Test(groups = ["modules"]) fun testPingsArray() { - assertThat(Ping.PINGS, "Pings array should be empty").isNotEmpty() + assertThat(Ping.PINGS, "Ping.PINGS").isNotEmpty() } @Test(groups = ["modules"]) fun testRandomPing() { for (i in 0..9) { - assertThat(Ping.PINGS, "Random ping $i").contains(randomPing()) + assertThat(Ping.PINGS, "Ping.PINGS[$i]").contains(randomPing()) } } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt index 24e3b67..162550f 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt @@ -34,6 +34,7 @@ package net.thauvin.erik.mobibot.modules import assertk.all import assertk.assertThat import assertk.assertions.hasNoCause +import assertk.assertions.index import assertk.assertions.isEqualTo import assertk.assertions.isFailure import assertk.assertions.isInstanceOf @@ -60,18 +61,21 @@ class StockQuoteTest : LocalProperties() { fun testGetQuote() { val apiKey = getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP) try { - val messages = getQuote("apple inc", apiKey) + var symbol = "apple inc" + val messages = getQuote(symbol, apiKey) assertThat(messages, "response not empty").isNotEmpty() - assertThat(messages[0].msg, "stock symbol should be AAPL").matches("Symbol: AAPL .*".toRegex()) - assertThat(messages[1].msg, "price label is invalid").matches(buildMatch("Price").toRegex()) - assertThat(messages[2].msg, "previous label is invalid").matches(buildMatch("Previous").toRegex()) - assertThat(messages[3].msg, "open label is invalid").matches(buildMatch("Open").toRegex()) + assertThat(messages, "getQuote($symbol)").index(0).prop(Message::msg).matches("Symbol: AAPL .*".toRegex()) + assertThat(messages, "getQuote($symbol)").index(1).prop(Message::msg).matches(buildMatch("Price").toRegex()) + assertThat(messages, "getQuote($symbol)").index(2).prop(Message::msg) + .matches(buildMatch("Previous").toRegex()) + assertThat(messages, "getQuote($symbol)").index(3).prop(Message::msg).matches(buildMatch("Open").toRegex()) - assertThat(getQuote("blahfoo", apiKey).first(), "symbol should be invalid").all { + symbol = "blahfoo" + assertThat(getQuote(symbol, apiKey).first(), "getQuote($symbol)").all { isInstanceOf(ErrorMessage::class.java) prop(Message::msg).isEqualTo(StockQuote.INVALID_SYMBOL) } - assertThat(getQuote("", "apikey").first(), "symbol should be empty").all { + assertThat(getQuote("", "apikey").first(), "getQuote(empty)").all { isInstanceOf(ErrorMessage::class.java) prop(Message::msg).isEqualTo(StockQuote.INVALID_SYMBOL) } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt index 2afcb88..6c67536 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt @@ -36,11 +36,13 @@ import assertk.assertThat import assertk.assertions.contains import assertk.assertions.endsWith import assertk.assertions.hasNoCause +import assertk.assertions.index import assertk.assertions.isEqualTo import assertk.assertions.isFailure import assertk.assertions.isInstanceOf import assertk.assertions.isNotNull import assertk.assertions.isTrue +import assertk.assertions.prop import net.aksingh.owmjapis.api.APIException import net.aksingh.owmjapis.core.OWM import net.thauvin.erik.mobibot.LocalProperties @@ -49,6 +51,7 @@ import net.thauvin.erik.mobibot.modules.Weather2.Companion.ftoC import net.thauvin.erik.mobibot.modules.Weather2.Companion.getCountry import net.thauvin.erik.mobibot.modules.Weather2.Companion.getWeather import net.thauvin.erik.mobibot.modules.Weather2.Companion.mphToKmh +import net.thauvin.erik.mobibot.msg.Message import org.testng.annotations.Test /** @@ -82,39 +85,42 @@ class Weather2Test : LocalProperties() { @Test(groups = ["modules"]) @Throws(ModuleException::class) fun testWeather() { - var messages = getWeather("98204", getProperty(OWM_API_KEY_PROP)) - assertThat(messages[0].msg, "city is not Everett").all { + var query = "98204" + var messages = getWeather(query, getProperty(OWM_API_KEY_PROP)) + assertThat(messages, "getWeather($query)").index(0).prop(Message::msg).all { contains("Everett, United States") contains("US") } - assertThat(messages[messages.size - 1].msg, "zip code is not Everett").endsWith("98204%2CUS") + assertThat(messages, "getWeather($query)").index(messages.size - 1).prop(Message::msg).endsWith("98204%2CUS") - messages = getWeather("San Francisco", getProperty(OWM_API_KEY_PROP)) - assertThat(messages[0].msg, "city is not San Francisco").all { + query = "San Francisco" + messages = getWeather(query, getProperty(OWM_API_KEY_PROP)) + assertThat(messages, "getWeather($query)").index(0).prop(Message::msg).all { contains("San Francisco") contains("US") } - assertThat(messages[messages.size - 1].msg, "city code is not San Fran").endsWith("5391959") + assertThat(messages, "getWeather($query)").index(messages.size - 1).prop(Message::msg).endsWith("5391959") - messages = getWeather("London, GB", getProperty(OWM_API_KEY_PROP)) - assertThat(messages[0].msg, "city is not London").all { + query = "London, GB" + messages = getWeather(query, getProperty(OWM_API_KEY_PROP)) + assertThat(messages, "getWeather($query)").index(0).prop(Message::msg).all { contains("London, United Kingdom") contains("GB") } - assertThat(messages[messages.size - 1].msg, "city code is not London").endsWith("2643743") + assertThat(messages, "getWeather($query)").index(messages.size - 1).prop(Message::msg).endsWith("2643743") try { - getWeather("Foo, US", getProperty(OWM_API_KEY_PROP)) + query = "Foo, US" + getWeather(query, getProperty(OWM_API_KEY_PROP)) } catch (e: ModuleException) { - assertThat(e.cause, "cause is not an API exception").isNotNull().isInstanceOf(APIException::class.java) + assertThat(e.cause, "getWeather($query)").isNotNull().isInstanceOf(APIException::class.java) } - assertThat { getWeather("test", "") }.isFailure() - .isInstanceOf(ModuleException::class.java).hasNoCause() - assertThat { getWeather("test", null) }.isFailure() - .isInstanceOf(ModuleException::class.java).hasNoCause() + query = "test" + assertThat { getWeather(query, "") }.isFailure().isInstanceOf(ModuleException::class.java).hasNoCause() + assertThat { getWeather(query, null) }.isFailure().isInstanceOf(ModuleException::class.java).hasNoCause() messages = getWeather("", "apikey") - assertThat(messages[0].isError, "empty query should be an error").isTrue() + assertThat(messages, "getWeather(empty)").index(0).prop(Message::isError).isTrue() } } diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WolframAlphaTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WolframAlphaTest.kt index 419486e..f5915ed 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WolframAlphaTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WolframAlphaTest.kt @@ -59,11 +59,13 @@ class WolframAlphaTest : LocalProperties() { fun queryWolframTest() { val apiKey = getProperty(WolframAlpha.WOLFRAM_APPID_KEY) try { - assertThat(WolframAlpha.queryWolfram("SFO to SEA", appId = apiKey), "SFO to SEA").contains("miles") + var query = "SFO to SEA" + assertThat(WolframAlpha.queryWolfram(query, appId = apiKey), "queryWolfram($query)").contains("miles") + query = "SFO to LAX" assertThat( - WolframAlpha.queryWolfram("SFO to LAX", WolframAlpha.METRIC, apiKey), - "SFO to LA" + WolframAlpha.queryWolfram(query, WolframAlpha.METRIC, apiKey), + "queryWolfram($query)" ).contains("kilometers") } catch (e: ModuleException) { // Avoid displaying api key in CI logs diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt index c2b061a..049d315 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt @@ -50,17 +50,17 @@ import java.time.ZoneId class WordTimeTest { @Test(groups = ["modules"]) fun testTime() { - assertThat(time(), "no zone").matches( + assertThat(time(), "time()").matches( ("The time is ${Colors.BOLD}\\d{1,2}:\\d{2}${Colors.BOLD} " + "on ${Colors.BOLD}\\w+, \\d{1,2} \\w+ \\d{4}${Colors.BOLD} " + "in ${Colors.BOLD}Los Angeles${Colors.BOLD}").toRegex() ) - assertThat(time(""), "zone is not LA").endsWith("Los Angeles".bold()) - assertThat(time("PST"), "zone is not PST").endsWith("Los Angeles".bold()) - assertThat(time("GB"), "zone is not London").endsWith("London".bold()) - assertThat(time("FR"), "zone is not Paris").endsWith("Paris".bold()) - assertThat(time("BLAH"), "zone should be unsupported").startsWith("Unsupported") - assertThat(time("BEAT"), "$BEATS_KEYWORD is invalid").matches("[\\w ]+ .?@\\d{3}+.? .beats".toRegex()) + assertThat(time(""), "time()").endsWith("Los Angeles".bold()) + assertThat(time("PST"), "time(PST)").endsWith("Los Angeles".bold()) + assertThat(time("GB"), "time(GB)").endsWith("London".bold()) + assertThat(time("FR"), "time(FR)").endsWith("Paris".bold()) + assertThat(time("BLAH"), "time(BLAH)").startsWith("Unsupported") + assertThat(time("BEAT"), "time($BEATS_KEYWORD)").matches("[\\w ]+ .?@\\d{3}+.? .beats".toRegex()) } @Test(groups = ["modules"]) diff --git a/version.properties b/version.properties index 10429b8..8d386c8 100644 --- a/version.properties +++ b/version.properties @@ -1,9 +1,9 @@ #Generated by the Semver Plugin for Gradle -#Sun Oct 02 07:45:05 PDT 2022 -version.buildmeta=689 +#Mon Oct 03 10:57:55 PDT 2022 +version.buildmeta=724 version.major=0 version.minor=8 version.patch=0 version.prerelease=rc version.project=mobibot -version.semver=0.8.0-rc+689 +version.semver=0.8.0-rc+724