Cleaned up tests.

This commit is contained in:
Erik C. Thauvin 2021-05-11 00:51:35 -07:00
parent 22e29d5ce3
commit faf40d3048
18 changed files with 123 additions and 117 deletions

View file

@ -74,25 +74,26 @@ class UtilsTest {
@Test @Test
fun testBold() { fun testBold() {
assertThat(bold(1)).`as`("bold(1)").isEqualTo(Colors.BOLD + "1" + Colors.BOLD) assertThat(bold(1)).describedAs("bold(1)").isEqualTo(Colors.BOLD + "1" + Colors.BOLD)
assertThat(bold(ascii)).`as`("bold(ascii)").isEqualTo(Colors.BOLD + ascii + Colors.BOLD) assertThat(bold(ascii)).describedAs("bold(ascii)").isEqualTo(Colors.BOLD + ascii + Colors.BOLD)
} }
@Test @Test
fun testCapitalize() { fun testCapitalize() {
assertThat(capitalize("test")).`as`("capitalize(test)").isEqualTo("Test") assertThat(capitalize("test")).describedAs("capitalize(test)").isEqualTo("Test")
assertThat(capitalize("Test")).`as`("capitalize(Test)").isEqualTo("Test") assertThat(capitalize("Test")).describedAs("capitalize(Test)").isEqualTo("Test")
assertThat(capitalize(null)).`as`("captitalize(null)").isNull() assertThat(capitalize(null)).describedAs("captitalize(null)").isNull()
assertThat(capitalize("")).`as`("capitalize()").isEqualTo("") assertThat(capitalize("")).describedAs("capitalize()").isEqualTo("")
} }
@Test @Test
fun testColorize() { fun testColorize() {
assertThat(colorize(ascii, Colors.REVERSE)).`as`("colorize(reverse)").isEqualTo( assertThat(colorize(ascii, Colors.REVERSE)).describedAs("colorize(reverse)").isEqualTo(
Colors.REVERSE + ascii + Colors.REVERSE Colors.REVERSE + ascii + Colors.REVERSE
) )
assertThat(colorize(ascii, Colors.RED)).`as`("colorize(red)").isEqualTo(Colors.RED + ascii + Colors.NORMAL) assertThat(colorize(ascii, Colors.RED)).describedAs("colorize(red)")
assertThat(colorize(null, Colors.RED)).`as`("colorize(null)").isEqualTo(Colors.NORMAL) .isEqualTo(Colors.RED + ascii + Colors.NORMAL)
assertThat(colorize(null, Colors.RED)).describedAs("colorize(null)").isEqualTo(Colors.NORMAL)
} }
@Test @Test
@ -102,15 +103,15 @@ class UtilsTest {
@Test @Test
fun testEnsureDir() { fun testEnsureDir() {
assertThat(ensureDir("dir", false)).`as`("ensureDir(dir, false)").isEqualTo("dir" + File.separatorChar) assertThat(ensureDir("dir", false)).describedAs("ensureDir(dir, false)").isEqualTo("dir" + File.separatorChar)
assertThat(ensureDir("https://erik.thauvin.net", true)).`as`("ensureDir(erik.thauvin.net, true)") assertThat(ensureDir("https://erik.thauvin.net", true)).describedAs("ensureDir(erik.thauvin.net, true)")
.isEqualTo("https://erik.thauvin.net/") .isEqualTo("https://erik.thauvin.net/")
} }
@Test @Test
fun testGetIntProperty() { fun testGetIntProperty() {
assertThat(getIntProperty("10", 1)).`as`("getIntProperty(10, 1)").isEqualTo(10) assertThat(getIntProperty("10", 1)).describedAs("getIntProperty(10, 1)").isEqualTo(10)
assertThat(getIntProperty("a", 1)).`as`("getIntProperty(a, 1)").isEqualTo(1) assertThat(getIntProperty("a", 1)).describedAs("getIntProperty(a, 1)").isEqualTo(1)
} }
@Test @Test
@ -120,25 +121,25 @@ class UtilsTest {
@Test @Test
fun testIsoLocalDate() { fun testIsoLocalDate() {
assertThat(isoLocalDate(cal.time)).`as`("isoLocalDate(date)").isEqualTo("1952-02-17") assertThat(isoLocalDate(cal.time)).describedAs("isoLocalDate(date)").isEqualTo("1952-02-17")
assertThat(isoLocalDate(localDateTime)).`as`("isoLocalDate(localDate)").isEqualTo("1952-02-17") assertThat(isoLocalDate(localDateTime)).describedAs("isoLocalDate(localDate)").isEqualTo("1952-02-17")
} }
@Test @Test
fun testObfuscate() { fun testObfuscate() {
assertThat(obfuscate(ascii).length).`as`("obfuscate is right length").isEqualTo(ascii.length) assertThat(obfuscate(ascii).length).describedAs("obfuscate is right length").isEqualTo(ascii.length)
assertThat(obfuscate(ascii)).`as`("obfuscate()").isEqualTo(StringUtils.repeat("x", ascii.length)) assertThat(obfuscate(ascii)).describedAs("obfuscate()").isEqualTo(StringUtils.repeat("x", ascii.length))
assertThat(obfuscate(" ")).`as`("obfuscate(blank)").isEqualTo(" ") assertThat(obfuscate(" ")).describedAs("obfuscate(blank)").isEqualTo(" ")
} }
@Test @Test
fun testPlural() { fun testPlural() {
val week = "week" val week = "week"
val weeks = "weeks" val weeks = "weeks"
assertThat(plural(-1, week, weeks)).`as`("plural(-1)").isEqualTo(week) assertThat(plural(-1, week, weeks)).describedAs("plural(-1)").isEqualTo(week)
assertThat(plural(0, week, weeks)).`as`("plural(0)").isEqualTo(week) assertThat(plural(0, week, weeks)).describedAs("plural(0)").isEqualTo(week)
assertThat(plural(1, week, weeks)).`as`("plural(1)").isEqualTo(week) assertThat(plural(1, week, weeks)).describedAs("plural(1)").isEqualTo(week)
assertThat(plural(2, week, weeks)).`as`("plural(2)").isEqualTo(weeks) assertThat(plural(2, week, weeks)).describedAs("plural(2)").isEqualTo(weeks)
} }
@Test @Test
@ -166,14 +167,14 @@ class UtilsTest {
@Test @Test
@Throws(IOException::class) @Throws(IOException::class)
fun testUrlReader() { fun testUrlReader() {
assertThat(urlReader(URL("https://postman-echo.com/status/200"))).`as`("urlReader()").isEqualTo( assertThat(urlReader(URL("https://postman-echo.com/status/200"))).describedAs("urlReader()")
"{\"status\":200}" .isEqualTo("{\"status\":200}"
) )
} }
@Test @Test
fun testUtcDateTime() { fun testUtcDateTime() {
assertThat(utcDateTime(cal.time)).`as`("utcDateTime(date)").isEqualTo("1952-02-17 12:30") assertThat(utcDateTime(cal.time)).describedAs("utcDateTime(date)").isEqualTo("1952-02-17 12:30")
assertThat(utcDateTime(localDateTime)).`as`("utcDateTime(localDate)").isEqualTo("1952-02-17 12:30") assertThat(utcDateTime(localDateTime)).describedAs("utcDateTime(localDate)").isEqualTo("1952-02-17 12:30")
} }
} }

View file

@ -51,17 +51,17 @@ class TellMessageTest {
val recipient = "recipient" val recipient = "recipient"
val sender = "sender" val sender = "sender"
val tellMessage = TellMessage(sender, recipient, message) val tellMessage = TellMessage(sender, recipient, message)
assertThat(tellMessage.sender).`as`(sender).isEqualTo(sender) assertThat(tellMessage.sender).describedAs(sender).isEqualTo(sender)
assertThat(tellMessage.recipient).`as`(recipient).isEqualTo(recipient) assertThat(tellMessage.recipient).describedAs(recipient).isEqualTo(recipient)
assertThat(tellMessage.message).`as`(message).isEqualTo(message) assertThat(tellMessage.message).describedAs(message).isEqualTo(message)
assertThat(isValidDate(tellMessage.queued)).`as`("queued is valid date/time").isTrue assertThat(isValidDate(tellMessage.queued)).describedAs("queued is valid date/time").isTrue
assertThat(tellMessage.isMatch(sender)).`as`("match sender").isTrue assertThat(tellMessage.isMatch(sender)).describedAs("match sender").isTrue
assertThat(tellMessage.isMatch(recipient)).`as`("match recipient").isTrue assertThat(tellMessage.isMatch(recipient)).describedAs("match recipient").isTrue
assertThat(tellMessage.isMatch("foo")).`as`("foo is no match").isFalse assertThat(tellMessage.isMatch("foo")).describedAs("foo is no match").isFalse
tellMessage.isReceived = true tellMessage.isReceived = true
assertThat(tellMessage.isReceived).`as`("is received").isTrue assertThat(tellMessage.isReceived).describedAs("is received").isTrue
assertThat(isValidDate(tellMessage.receptionDate)).`as`("received is valid date/time").isTrue assertThat(isValidDate(tellMessage.receptionDate)).describedAs("received is valid date/time").isTrue
tellMessage.isNotified = true tellMessage.isNotified = true
assertThat(tellMessage.isNotified).`as`("is notified").isTrue assertThat(tellMessage.isNotified).describedAs("is notified").isTrue
} }
} }

View file

@ -56,37 +56,37 @@ class EntryLinkTest {
entryLink.addComment("c$i", "u$i") entryLink.addComment("c$i", "u$i")
i++ i++
} }
assertThat(entryLink.comments.size).`as`("getComments().size() == 5").isEqualTo(i) assertThat(entryLink.comments.size).describedAs("getComments().size() == 5").isEqualTo(i)
i = 0 i = 0
for (comment in entryLink.comments) { for (comment in entryLink.comments) {
assertThat(comment.comment).`as`("getComment($i)").isEqualTo("c$i") assertThat(comment.comment).describedAs("getComment($i)").isEqualTo("c$i")
assertThat(comment.nick).`as`("getNick($i)").isEqualTo("u$i") assertThat(comment.nick).describedAs("getNick($i)").isEqualTo("u$i")
i++ i++
} }
val r = SecureRandom() val r = SecureRandom()
while (entryLink.comments.size > 0) { while (entryLink.comments.size > 0) {
entryLink.deleteComment(r.nextInt(entryLink.comments.size)) entryLink.deleteComment(r.nextInt(entryLink.comments.size))
} }
assertThat(entryLink.comments.isNotEmpty()).`as`("hasComments()").isFalse assertThat(entryLink.comments.isNotEmpty()).describedAs("hasComments()").isFalse
entryLink.addComment("nothing", "nobody") entryLink.addComment("nothing", "nobody")
entryLink.setComment(0, "something", "somebody") entryLink.setComment(0, "something", "somebody")
assertThat(entryLink.getComment(0).nick).`as`("getNick(somebody)").isEqualTo("somebody") assertThat(entryLink.getComment(0).nick).describedAs("getNick(somebody)").isEqualTo("somebody")
assertThat(entryLink.getComment(0).comment).`as`("getComment(something)").isEqualTo("something") assertThat(entryLink.getComment(0).comment).describedAs("getComment(something)").isEqualTo("something")
} }
@Test @Test
fun testTags() { fun testTags() {
val tags: List<SyndCategory> = entryLink.tags val tags: List<SyndCategory> = entryLink.tags
for ((i, tag) in tags.withIndex()) { for ((i, tag) in tags.withIndex()) {
assertThat(tag.name).`as`("tag.getName($i)").isEqualTo("tag" + (i + 1)) assertThat(tag.name).describedAs("tag.getName($i)").isEqualTo("tag" + (i + 1))
} }
assertThat(entryLink.tags.size).`as`("getTags().size() is 5").isEqualTo(5) assertThat(entryLink.tags.size).describedAs("getTags().size() is 5").isEqualTo(5)
assertThat(entryLink.tags.isNotEmpty()).`as`("hasTags() is true").isTrue assertThat(entryLink.tags.isNotEmpty()).describedAs("hasTags() is true").isTrue
entryLink.setTags("-tag5") entryLink.setTags("-tag5")
entryLink.setTags("+mobitopia") entryLink.setTags("+mobitopia")
entryLink.setTags("tag4") entryLink.setTags("tag4")
entryLink.setTags("-mobitopia") entryLink.setTags("-mobitopia")
assertThat(entryLink.pinboardTags).`as`("getPinboardTags()") assertThat(entryLink.pinboardTags).describedAs("getPinboardTags()")
.isEqualTo(entryLink.nick + ",tag1,tag2,tag3,tag4,mobitopia") .isEqualTo(entryLink.nick + ",tag1,tag2,tag3,tag4,mobitopia")
} }
} }

View file

@ -44,10 +44,11 @@ import org.testng.annotations.Test
class CalcTest { class CalcTest {
@Test @Test
fun testCalculate() { fun testCalculate() {
assertThat(calculate("1 + 1")).`as`("calculate(1+1)").isEqualTo("1+1 = %s", Utils.bold(2)) assertThat(calculate("1 + 1")).describedAs("calculate(1+1)").isEqualTo("1+1 = %s", Utils.bold(2))
assertThat(calculate("1 -3")).`as`("calculate(1 -3)").isEqualTo("1-3 = %s", Utils.bold(-2)) assertThat(calculate("1 -3")).describedAs("calculate(1 -3)").isEqualTo("1-3 = %s", Utils.bold(-2))
assertThat(calculate("pi+π+e+φ")).`as`("calculate(pi+π+e+φ)").isEqualTo("pi+π+e+φ = %s", Utils.bold("10.62")) assertThat(calculate("pi+π+e+φ")).describedAs("calculate(pi+π+e+φ)")
assertThatThrownBy { calculate("one + one") }.`as`("calculate(one+one)") .isEqualTo("pi+π+e+φ = %s", Utils.bold("10.62"))
.isInstanceOf(UnknownFunctionOrVariableException::class.java) assertThatThrownBy { calculate("one + one") }.describedAs("calculate(one+one)")
.isInstanceOf(UnknownFunctionOrVariableException::class.java)
} }
} }

View file

@ -31,9 +31,8 @@
*/ */
package net.thauvin.erik.mobibot.modules package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
import net.thauvin.erik.crypto.CryptoException import net.thauvin.erik.crypto.CryptoException
import net.thauvin.erik.mobibot.LocalProperties import net.thauvin.erik.crypto.CryptoPrice.Companion.marketPrice
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy import org.assertj.core.api.Assertions.assertThatThrownBy
import org.testng.annotations.Test import org.testng.annotations.Test
@ -46,28 +45,28 @@ class CryptoPricesTest {
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun testMarketPrice() { fun testMarketPrice() {
var price = marketPrice("BTC", "USD") var price = marketPrice("BTC", "USD")
assertThat(price.base).`as`("is BTC").isEqualTo("BTC") assertThat(price.base).describedAs("is BTC").isEqualTo("BTC")
assertThat(price.currency).`as`("is USD").isEqualTo("USD") assertThat(price.currency).describedAs("is USD").isEqualTo("USD")
assertThat(price.amount).`as`("BTC > 0").isGreaterThan(0.00) assertThat(price.amount).describedAs("BTC > 0").isGreaterThan(0.00)
price = marketPrice("ETH", "EUR") price = marketPrice("ETH", "EUR")
assertThat(price.base).`as`("is ETH").isEqualTo("ETH") assertThat(price.base).describedAs("is ETH").isEqualTo("ETH")
assertThat(price.currency).`as`("is EUR").isEqualTo("EUR") assertThat(price.currency).describedAs("is EUR").isEqualTo("EUR")
assertThat(price.amount).`as`("ETH > 0").isGreaterThan(0.00) assertThat(price.amount).describedAs("ETH > 0").isGreaterThan(0.00)
price = marketPrice("ETH2", "GBP") price = marketPrice("ETH2", "GBP")
assertThat(price.base).`as`("is ETH2").isEqualTo("ETH2") assertThat(price.base).describedAs("is ETH2").isEqualTo("ETH2")
assertThat(price.currency).`as`("is GBP").isEqualTo("GBP") assertThat(price.currency).describedAs("is GBP").isEqualTo("GBP")
assertThat(price.amount).`as`("ETH2 > 0").isGreaterThan(0.00) assertThat(price.amount).describedAs("ETH2 > 0").isGreaterThan(0.00)
assertThatThrownBy { marketPrice("FOO", "USD") } assertThatThrownBy { marketPrice("FOO", "USD") }
.`as`("FOO") .describedAs("FOO")
.isInstanceOf(CryptoException::class.java) .isInstanceOf(CryptoException::class.java)
.hasMessageContaining("Invalid base currency") .hasMessageContaining("Invalid base currency")
assertThatThrownBy { marketPrice("FOO", "BAR") } assertThatThrownBy { marketPrice("FOO", "BAR") }
.`as`("FOO-BAR") .describedAs("FOO-BAR")
.isInstanceOf(CryptoException::class.java) .isInstanceOf(CryptoException::class.java)
.hasMessageContaining("Invalid currency (BAR)") .hasMessageContaining("Invalid currency (BAR)")
} }
} }

View file

@ -51,10 +51,11 @@ class CurrencyConverterTest {
@Test @Test
fun testConvertCurrency() { fun testConvertCurrency() {
assertThat(convertCurrency("100 USD to EUR").msg) assertThat(convertCurrency("100 USD to EUR").msg)
.`as`("100 USD to EUR").matches("100\\.00 USD = \\d{2,3}\\.\\d{2} EUR") .describedAs("100 USD to EUR").matches("100\\.00 USD = \\d{2,3}\\.\\d{2} EUR")
assertThat(convertCurrency("100 USD to USD").msg).`as`("100 USD to USD").contains("You're kidding, right?") assertThat(convertCurrency("100 USD to USD").msg).describedAs("100 USD to USD")
assertThat(convertCurrency("100 USD").msg).`as`("100 USD").contains("Invalid query.") .contains("You're kidding, right?")
assertThat(currencyRates().size).`as`("currencyRates().size() == 33").isEqualTo(33) assertThat(convertCurrency("100 USD").msg).describedAs("100 USD").contains("Invalid query.")
assertThat(currencyRates()).`as`("currencyRates().get(EUR)").contains(" EUR: 1") assertThat(currencyRates().size).describedAs("currencyRates().size() == 33").isEqualTo(33)
assertThat(currencyRates()).describedAs("currencyRates().get(EUR)").contains(" EUR: 1")
} }
} }

View file

@ -39,8 +39,8 @@ import org.testng.annotations.Test
class DiceTest { class DiceTest {
@Test @Test
fun testWinLoseOrTie() { fun testWinLoseOrTie() {
assertThat(Dice.winLoseOrTie(6, 6)).`as`("6 vs. 6").isEqualTo(Dice.Result.TIE) assertThat(Dice.winLoseOrTie(6, 6)).describedAs("6 vs. 6").isEqualTo(Dice.Result.TIE)
assertThat(Dice.winLoseOrTie(6, 5)).`as`("6 vs. 5").isEqualTo(Dice.Result.WIN) assertThat(Dice.winLoseOrTie(6, 5)).describedAs("6 vs. 5").isEqualTo(Dice.Result.WIN)
assertThat(Dice.winLoseOrTie(5, 6)).`as`("5 vs. 6").isEqualTo(Dice.Result.LOSE) assertThat(Dice.winLoseOrTie(5, 6)).describedAs("5 vs. 6").isEqualTo(Dice.Result.LOSE)
} }
} }

View file

@ -48,19 +48,19 @@ class GoogleSearchTest : LocalProperties() {
val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP) val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP)
try { try {
var messages = searchGoogle("mobitopia", apiKey, cseKey) var messages = searchGoogle("mobitopia", apiKey, cseKey)
assertThat(messages).`as`("mobitopia results not empty").isNotEmpty assertThat(messages).describedAs("mobitopia results not empty").isNotEmpty
assertThat(messages[0].msg).`as`("found freenode").contains("freenode") assertThat(messages[0].msg).describedAs("found freenode").contains("freenode")
messages = searchGoogle("aapl", apiKey, cseKey) messages = searchGoogle("aapl", apiKey, cseKey)
assertThat(messages).`as`("aapl results not empty").isNotEmpty assertThat(messages).describedAs("aapl results not empty").isNotEmpty
assertThat(messages[0].msg).`as`("found apple").containsIgnoringCase("apple") assertThat(messages[0].msg).describedAs("found apple").containsIgnoringCase("apple")
assertThatThrownBy { searchGoogle("test", "", "apiKey") } assertThatThrownBy { searchGoogle("test", "", "apiKey") }
.`as`("no API key") .describedAs("no API key")
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java).hasNoCause()
assertThatThrownBy { searchGoogle("test", "apiKey", "") } assertThatThrownBy { searchGoogle("test", "apiKey", "") }
.`as`("no CSE API key") .describedAs("no CSE API key")
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java).hasNoCause()
assertThatThrownBy { searchGoogle("", "apikey", "apiKey") } assertThatThrownBy { searchGoogle("", "apikey", "apiKey") }
.`as`("no query").isInstanceOf(ModuleException::class.java).hasNoCause() .describedAs("no query").isInstanceOf(ModuleException::class.java).hasNoCause()
} catch (e: ModuleException) { } catch (e: ModuleException) {
// Avoid displaying api keys in CI logs // Avoid displaying api keys in CI logs
if ("true" == System.getenv("CI") && apiKey.isNotBlank() && cseKey.isNotBlank()) { if ("true" == System.getenv("CI") && apiKey.isNotBlank() && cseKey.isNotBlank()) {

View file

@ -42,7 +42,7 @@ class JokeTest {
@Test @Test
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun testRamdomJoke() { fun testRamdomJoke() {
assertThat(randomJoke().msg.isNotEmpty()).`as`("randomJoke() > 0").isTrue assertThat(randomJoke().msg.isNotEmpty()).describedAs("randomJoke() > 0").isTrue
assertThat(randomJoke().msg).`as`("randomJoke()").containsIgnoringCase("chuck") assertThat(randomJoke().msg).describedAs("randomJoke()").containsIgnoringCase("chuck")
} }
} }

View file

@ -44,7 +44,7 @@ class LookupTest {
@Throws(Exception::class) @Throws(Exception::class)
fun testLookup() { fun testLookup() {
val result = nslookup("apple.com") val result = nslookup("apple.com")
assertThat(result).`as`("lookup(apple.com)").contains("17.253.144.10") assertThat(result).describedAs("lookup(apple.com)").contains("17.253.144.10")
} }
@Test @Test
@ -52,6 +52,6 @@ class LookupTest {
fun testWhois() { fun testWhois() {
val result = whois("17.178.96.59", Lookup.WHOIS_HOST) val result = whois("17.178.96.59", Lookup.WHOIS_HOST)
assertThat(result.stream().anyMatch { m: String -> m.contains("Apple Inc.") }) assertThat(result.stream().anyMatch { m: String -> m.contains("Apple Inc.") })
.`as`("whois(17.178.96.59/Apple Inc.").isTrue .describedAs("whois(17.178.96.59/Apple Inc.").isTrue
} }
} }

View file

@ -50,7 +50,7 @@ class ModuleExceptionTest {
fun createData(@Suppress("UNUSED_PARAMETER") m: Method?): Array<Array<Any>> { fun createData(@Suppress("UNUSED_PARAMETER") m: Method?): Array<Array<Any>> {
return arrayOf( return arrayOf(
arrayOf(ModuleException(debugMessage, message, IOException("URL http://foobar.com"))), arrayOf(ModuleException(debugMessage, message, IOException("URL http://foobar.com"))),
arrayOf(ModuleException(debugMessage,message,IOException("URL http://foobar.com?"))), arrayOf(ModuleException(debugMessage, message, IOException("URL http://foobar.com?"))),
arrayOf(ModuleException(debugMessage, message)) arrayOf(ModuleException(debugMessage, message))
) )
} }

View file

@ -41,13 +41,13 @@ import org.testng.annotations.Test
class PingTest { class PingTest {
@Test @Test
fun testPingsArray() { fun testPingsArray() {
assertThat(Ping.PINGS).`as`("Pings array is not empty.").isNotEmpty assertThat(Ping.PINGS).describedAs("Pings array is not empty.").isNotEmpty
} }
@Test @Test
fun testRandomPing() { fun testRandomPing() {
for (i in 0..9) { for (i in 0..9) {
assertThat(randomPing()).`as`("Random ping $i").isIn(Ping.PINGS) assertThat(randomPing()).describedAs("Random ping $i").isIn(Ping.PINGS)
} }
} }
} }

View file

@ -38,13 +38,17 @@ import org.testng.annotations.Test
class RockPaperScissorsTest { class RockPaperScissorsTest {
@Test @Test
fun testWinLoseOrDraw() { fun testWinLoseOrDraw() {
assertThat(RockPaperScissors.winLoseOrDraw("scissors", "paper")).`as`("scissors vs. paper").isEqualTo("win") assertThat(RockPaperScissors.winLoseOrDraw("scissors", "paper")).describedAs("scissors vs. paper")
assertThat(RockPaperScissors.winLoseOrDraw("paper", "rock")).`as`("paper vs. rock").isEqualTo("win") .isEqualTo("win")
assertThat(RockPaperScissors.winLoseOrDraw("rock", "scissors")).`as`("rock vs. scissors").isEqualTo("win") assertThat(RockPaperScissors.winLoseOrDraw("paper", "rock")).describedAs("paper vs. rock").isEqualTo("win")
assertThat(RockPaperScissors.winLoseOrDraw("paper", "scissors")).`as`("paper vs. scissors").isEqualTo("lose") assertThat(RockPaperScissors.winLoseOrDraw("rock", "scissors")).describedAs("rock vs. scissors")
assertThat(RockPaperScissors.winLoseOrDraw("rock", "paper")).`as`("rock vs. paper").isEqualTo("lose") .isEqualTo("win")
assertThat(RockPaperScissors.winLoseOrDraw("scissors", "rock")).`as`("scissors vs. rock").isEqualTo("lose") assertThat(RockPaperScissors.winLoseOrDraw("paper", "scissors")).describedAs("paper vs. scissors")
.isEqualTo("lose")
assertThat(RockPaperScissors.winLoseOrDraw("rock", "paper")).describedAs("rock vs. paper").isEqualTo("lose")
assertThat(RockPaperScissors.winLoseOrDraw("scissors", "rock")).describedAs("scissors vs. rock")
.isEqualTo("lose")
assertThat(RockPaperScissors.winLoseOrDraw("scissors", "scissors")) assertThat(RockPaperScissors.winLoseOrDraw("scissors", "scissors"))
.`as`("scissors vs. scissors").isEqualTo("draw") .describedAs("scissors vs. scissors").isEqualTo("draw")
} }
} }

View file

@ -47,17 +47,17 @@ class StockQuoteTest : LocalProperties() {
val apiKey = getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP) val apiKey = getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP)
try { try {
val messages = getQuote("apple inc", apiKey) val messages = getQuote("apple inc", apiKey)
assertThat(messages).`as`("response not empty").isNotEmpty assertThat(messages).describedAs("response not empty").isNotEmpty
assertThat(messages[0].msg).`as`("same stock symbol").startsWith("Symbol: AAPL") assertThat(messages[0].msg).describedAs("same stock symbol").startsWith("Symbol: AAPL")
assertThat(messages[1].msg).`as`("price label").startsWith(" Price: ") assertThat(messages[1].msg).describedAs("price label").startsWith(" Price: ")
try { try {
getQuote("blahfoo", apiKey) getQuote("blahfoo", apiKey)
} catch (e: ModuleException) { } catch (e: ModuleException) {
assertThat(e.message).`as`("invalid symbol").containsIgnoringCase(StockQuote.INVALID_SYMBOL) assertThat(e.message).describedAs("invalid symbol").containsIgnoringCase(StockQuote.INVALID_SYMBOL)
} }
assertThatThrownBy { getQuote("test", "") }.`as`("no API key") assertThatThrownBy { getQuote("test", "") }.describedAs("no API key")
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java).hasNoCause()
assertThatThrownBy { getQuote("", "apikey") }.`as`("no symbol") assertThatThrownBy { getQuote("", "apikey") }.describedAs("no symbol")
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java).hasNoCause()
} catch (e: ModuleException) { } catch (e: ModuleException) {
// Avoid displaying api keys in CI logs // Avoid displaying api keys in CI logs

View file

@ -66,6 +66,6 @@ class TwitterTest : LocalProperties() {
msg, msg,
true true
).msg ).msg
).`as`("twitterPost($msg)").isEqualTo(msg) ).describedAs("twitterPost($msg)").isEqualTo(msg)
} }
} }

View file

@ -46,16 +46,16 @@ class Weather2Test : LocalProperties() {
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun testWeather() { fun testWeather() {
var messages = getWeather("98204", getProperty(Weather2.OWM_API_KEY_PROP)) var messages = getWeather("98204", getProperty(Weather2.OWM_API_KEY_PROP))
assertThat(messages[0].msg).`as`("is Everett").contains("Everett").contains("US") assertThat(messages[0].msg).describedAs("is Everett").contains("Everett").contains("US")
assertThat(messages[messages.size - 1].msg).`as`("is City Search").endsWith("98204%2CUS") assertThat(messages[messages.size - 1].msg).describedAs("is City Search").endsWith("98204%2CUS")
messages = getWeather("London, UK", getProperty(Weather2.OWM_API_KEY_PROP)) messages = getWeather("London, UK", getProperty(Weather2.OWM_API_KEY_PROP))
assertThat(messages[0].msg).`as`("is UK").contains("London").contains("UK") assertThat(messages[0].msg).describedAs("is UK").contains("London").contains("UK")
assertThat(messages[messages.size - 1].msg).`as`("is City Code").endsWith("4517009") assertThat(messages[messages.size - 1].msg).describedAs("is City Code").endsWith("4517009")
assertThatThrownBy { getWeather("Montpellier, FR", getProperty(Weather2.OWM_API_KEY_PROP)) } assertThatThrownBy { getWeather("Montpellier, FR", getProperty(Weather2.OWM_API_KEY_PROP)) }
.`as`("Montpellier not found").hasCauseInstanceOf(APIException::class.java) .describedAs("Montpellier not found").hasCauseInstanceOf(APIException::class.java)
assertThatThrownBy { getWeather("test", "") } assertThatThrownBy { getWeather("test", "") }
.`as`("no API key").isInstanceOf(ModuleException::class.java).hasNoCause() .describedAs("no API key").isInstanceOf(ModuleException::class.java).hasNoCause()
messages = getWeather("", "apikey") messages = getWeather("", "apikey")
assertThat(messages[0].isError).`as`("no query").isTrue assertThat(messages[0].isError).describedAs("no query").isTrue
} }
} }

View file

@ -42,8 +42,8 @@ import org.testng.annotations.Test
class WordTimeTest { class WordTimeTest {
@Test @Test
fun testTime() { fun testTime() {
assertThat(time("PST").msg).`as`("PST").endsWith(Utils.bold("Los Angeles")) assertThat(time("PST").msg).describedAs("PST").endsWith(Utils.bold("Los Angeles"))
assertThat(time("BLAH").isError).`as`("BLAH").isTrue assertThat(time("BLAH").isError).describedAs("BLAH").isTrue
assertThat(time("BEATS").msg).`as`("BEATS").contains("@") assertThat(time("BEATS").msg).describedAs("BEATS").contains("@")
} }
} }

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle #Generated by the Semver Plugin for Gradle
#Tue May 11 00:11:43 PDT 2021 #Tue May 11 00:47:17 PDT 2021
version.buildmeta=720 version.buildmeta=722
version.major=0 version.major=0
version.minor=8 version.minor=8
version.patch=0 version.patch=0
version.prerelease=beta version.prerelease=beta
version.project=mobibot version.project=mobibot
version.semver=0.8.0-beta+720 version.semver=0.8.0-beta+722