From acf56b2178ca6f88e115df41923e17197ded1a78 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 24 Sep 2022 10:54:56 -0700 Subject: [PATCH] Cleaned up tests --- .../mobibot/modules/CurrencyConverterTest.kt | 10 +++++----- .../thauvin/erik/mobibot/modules/DiceTest.kt | 10 +++++----- .../erik/mobibot/modules/GoogleSearchTest.kt | 4 ++-- .../mobibot/modules/ModuleExceptionTest.kt | 18 ++++++++--------- .../thauvin/erik/mobibot/modules/PingTest.kt | 2 +- .../erik/mobibot/modules/StockQuoteTest.kt | 12 +++++------ .../erik/mobibot/modules/Weather2Test.kt | 20 +++++++++---------- .../erik/mobibot/modules/WordTimeTest.kt | 12 +++++------ version.properties | 6 +++--- 9 files changed, 47 insertions(+), 47 deletions(-) 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 0cd20fe..4102e6b 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" + "100 USD to EUR is invalid" ).matches("100 United States Dollar = \\d{2,3}\\.\\d+ Euro".toRegex()) assertThat( convertCurrency("1 USD to BTC").msg, - "1 USD to BTC" + "1 USD to BTC is invalid" ).matches("1 United States Dollar = 0\\.\\d+ Bitcoin".toRegex()) assertThat( convertCurrency("100,000.00 GBP to BTC").msg, - "100 USD to EUR" + "100 USD to EUR is invalid" ).matches("100,000.00 British Pound Sterling = \\d{1,2}\\.\\d+ Bitcoin".toRegex()) - assertThat(convertCurrency("100 USD to USD"), "100 USD to USD").all { + assertThat(convertCurrency("100 USD to USD"), "100 USD to USD is invalid").all { prop(Message::msg).contains("You're kidding, right?") isInstanceOf(PublicMessage::class.java) } - assertThat(convertCurrency("100 USD"), "100 USD").all { + assertThat(convertCurrency("100 USD"), "100 USD should be invalid").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 e07037c..85db410 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").isEqualTo("\u00021\u0002") - assertThat(Dice.roll(2, 1), "2d1") + assertThat(Dice.roll(1, 1), "1d1 is invalid").isEqualTo("\u00021\u0002") + assertThat(Dice.roll(2, 1), "2d1 is invalid") .isEqualTo("\u00021\u0002 + \u00021\u0002 = \u00022\u0002") - assertThat(Dice.roll(5, 1), "5d1") + assertThat(Dice.roll(5, 1), "5d1 is invalid") .isEqualTo("\u00021\u0002 + \u00021\u0002 + \u00021\u0002 + \u00021\u0002 + \u00021\u0002 = \u00025\u0002") - assertThat(Dice.roll(2, 6), "2d6") + assertThat(Dice.roll(2, 6), "2d6 is invalid") .matches("\u0002[1-6]\u0002 \\+ \u0002[1-6]\u0002 = \u0002[1-9][0-2]?\u0002".toRegex()) - assertThat(Dice.roll(3, 7), "3d7") + assertThat(Dice.roll(3, 7), "3d7 is invalid") .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 7c15d32..41931c0 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt @@ -79,8 +79,8 @@ class GoogleSearchTest : LocalProperties() { try { var messages = searchGoogle("mobibot", apiKey, cseKey) - assertThat(messages, "mobibot results not empty").isNotEmpty() - assertThat(messages[0].msg, "found mobibot").contains("mobibot", true) + assertThat(messages, "search result should not be empty").isNotEmpty() + assertThat(messages[0].msg, "search query not found").contains("mobibot", true) messages = searchGoogle("adadflkjl", apiKey, cseKey) assertThat(messages[0], "not found").all { 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 49fc5a9..65513d4 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/ModuleExceptionTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/ModuleExceptionTest.kt @@ -66,41 +66,41 @@ class ModuleExceptionTest { @Test(dataProvider = "dp") fun testGetDebugMessage(e: ModuleException) { - assertThat(e.debugMessage, "get debug message").isEqualTo(debugMessage) + assertThat(e.debugMessage, "debug message is invalid").isEqualTo(debugMessage) } @Test(dataProvider = "dp") fun testGetMessage(e: ModuleException) { - assertThat(e, "get message").hasMessage(message) + assertThat(e, "message is invalid").hasMessage(message) } @Test(groups = ["modules"]) 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").isNotNull().all { + assertThat(e.sanitize(apiKey, "", "me").message, "sanitized url is invalid").isNotNull().all { contains("xxxxxxxxxx", "userID=xx", "java.io.IOException") doesNotContain(apiKey, "me") } e = ModuleException(debugMessage, message, null) - assertThat(e.sanitize(apiKey), "no cause").hasMessage(message) + assertThat(e.sanitize(apiKey), "cause should be null").hasMessage(message) e = ModuleException(debugMessage, message, IOException()) - assertThat(e.sanitize(apiKey), "no cause message").hasMessage(message) + assertThat(e.sanitize(apiKey), "cause message is invalid").hasMessage(message) e = ModuleException(debugMessage, apiKey) - assertThat(e.sanitize(apiKey).message, "api key in message").isNotNull().doesNotContain(apiKey) + assertThat(e.sanitize(apiKey).message, "message should not contain api key").isNotNull().doesNotContain(apiKey) val msg: String? = null e = ModuleException(debugMessage, msg, IOException(msg)) - assertThat(e.sanitize(apiKey).message, "null message").isNull() + assertThat(e.sanitize(apiKey).message, "message should be null").isNull() e = ModuleException(debugMessage, msg, IOException("foo is $apiKey")) - assertThat(e.sanitize(" ", apiKey, "foo").message, "key in cause").isNotNull().all { + assertThat(e.sanitize(" ", apiKey, "foo").message, "message should not contain key").isNotNull().all { doesNotContain(apiKey) endsWith("xxx is xxxxxxxxxx") } - assertThat(e.sanitize(), "empty").isEqualTo(e) + assertThat(e.sanitize(), "exception should be unchanged").isEqualTo(e) } } 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 f17e1fa..d944047 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/PingTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/PingTest.kt @@ -43,7 +43,7 @@ import org.testng.annotations.Test class PingTest { @Test(groups = ["modules"]) fun testPingsArray() { - assertThat(Ping.PINGS, "Pings array is not empty.").isNotEmpty() + assertThat(Ping.PINGS, "Pings array should be empty").isNotEmpty() } @Test(groups = ["modules"]) 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 81f77bd..24e3b67 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt @@ -62,16 +62,16 @@ class StockQuoteTest : LocalProperties() { try { val messages = getQuote("apple inc", apiKey) assertThat(messages, "response not empty").isNotEmpty() - assertThat(messages[0].msg, "same stock symbol").matches("Symbol: AAPL .*".toRegex()) - assertThat(messages[1].msg, "price label").matches(buildMatch("Price").toRegex()) - assertThat(messages[2].msg, "previous label").matches(buildMatch("Previous").toRegex()) - assertThat(messages[3].msg, "open label").matches(buildMatch("Open").toRegex()) + 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(getQuote("blahfoo", apiKey).first(), "invalid symbol").all { + assertThat(getQuote("blahfoo", apiKey).first(), "symbol should be invalid").all { isInstanceOf(ErrorMessage::class.java) prop(Message::msg).isEqualTo(StockQuote.INVALID_SYMBOL) } - assertThat(getQuote("", "apikey").first(), "empty symbol").all { + assertThat(getQuote("", "apikey").first(), "symbol should be 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 ebd704b..2afcb88 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt @@ -63,8 +63,8 @@ class Weather2Test : LocalProperties() { @Test(groups = ["modules"]) fun testGetCountry() { - assertThat(getCountry("foo"), "not a country").isEqualTo(OWM.Country.UNITED_STATES) - assertThat(getCountry("fr"), "fr is france").isEqualTo(OWM.Country.FRANCE) + assertThat(getCountry("foo"), "foo is not a valid country").isEqualTo(OWM.Country.UNITED_STATES) + assertThat(getCountry("fr"), "country should France").isEqualTo(OWM.Country.FRANCE) val country = OWM.Country.values() repeat(3) { @@ -83,30 +83,30 @@ class Weather2Test : LocalProperties() { @Throws(ModuleException::class) fun testWeather() { var messages = getWeather("98204", getProperty(OWM_API_KEY_PROP)) - assertThat(messages[0].msg, "is Everett").all { + assertThat(messages[0].msg, "city is not Everett").all { contains("Everett, United States") contains("US") } - assertThat(messages[messages.size - 1].msg, "is Everett zip code").endsWith("98204%2CUS") + assertThat(messages[messages.size - 1].msg, "zip code is not Everett").endsWith("98204%2CUS") messages = getWeather("San Francisco", getProperty(OWM_API_KEY_PROP)) - assertThat(messages[0].msg, "is San Francisco").all { + assertThat(messages[0].msg, "city is not San Francisco").all { contains("San Francisco") contains("US") } - assertThat(messages[messages.size - 1].msg, "is San Fran city code").endsWith("5391959") + assertThat(messages[messages.size - 1].msg, "city code is not San Fran").endsWith("5391959") messages = getWeather("London, GB", getProperty(OWM_API_KEY_PROP)) - assertThat(messages[0].msg, "is UK").all { + assertThat(messages[0].msg, "city is not London").all { contains("London, United Kingdom") contains("GB") } - assertThat(messages[messages.size - 1].msg, "is London city code").endsWith("2643743") + assertThat(messages[messages.size - 1].msg, "city code is not London").endsWith("2643743") try { getWeather("Foo, US", getProperty(OWM_API_KEY_PROP)) } catch (e: ModuleException) { - assertThat(e.cause, "cause is API exception").isNotNull().isInstanceOf(APIException::class.java) + assertThat(e.cause, "cause is not an API exception").isNotNull().isInstanceOf(APIException::class.java) } assertThat { getWeather("test", "") }.isFailure() @@ -115,6 +115,6 @@ class Weather2Test : LocalProperties() { .isInstanceOf(ModuleException::class.java).hasNoCause() messages = getWeather("", "apikey") - assertThat(messages[0].isError, "no query").isTrue() + assertThat(messages[0].isError, "empty query should be an error").isTrue() } } 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 31e3d4a..c2b061a 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt @@ -55,12 +55,12 @@ class WordTimeTest { "on ${Colors.BOLD}\\w+, \\d{1,2} \\w+ \\d{4}${Colors.BOLD} " + "in ${Colors.BOLD}Los Angeles${Colors.BOLD}").toRegex() ) - assertThat(time(""), "empty zone").endsWith("Los Angeles".bold()) - assertThat(time("PST"), "PST").endsWith("Los Angeles".bold()) - assertThat(time("GB"), "GB").endsWith("London".bold()) - assertThat(time("FR"), "FR").endsWith("Paris".bold()) - assertThat(time("BLAH"), "BLAH").startsWith("Unsupported") - assertThat(time("BEAT"), BEATS_KEYWORD).matches("[\\w ]+ .?@\\d{3}+.? .beats".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()) } @Test(groups = ["modules"]) diff --git a/version.properties b/version.properties index 6abe999..f527416 100644 --- a/version.properties +++ b/version.properties @@ -1,9 +1,9 @@ #Generated by the Semver Plugin for Gradle -#Mon Sep 19 01:34:05 PDT 2022 -version.buildmeta=667 +#Sat Sep 24 10:52:55 PDT 2022 +version.buildmeta=676 version.major=0 version.minor=8 version.patch=0 version.prerelease=rc version.project=mobibot -version.semver=0.8.0-rc+667 +version.semver=0.8.0-rc+676