Cleanup tests.

This commit is contained in:
Erik C. Thauvin 2021-04-28 08:23:14 -07:00
parent 2f4e6bdb2d
commit 21cbecff8e
16 changed files with 120 additions and 149 deletions

View file

@ -48,7 +48,7 @@ import net.thauvin.erik.mobibot.Utils.uptime
import net.thauvin.erik.mobibot.Utils.urlReader import net.thauvin.erik.mobibot.Utils.urlReader
import net.thauvin.erik.mobibot.Utils.utcDateTime import net.thauvin.erik.mobibot.Utils.utcDateTime
import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.StringUtils
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.jibble.pircbot.Colors import org.jibble.pircbot.Colors
import org.testng.annotations.BeforeClass import org.testng.annotations.BeforeClass
import org.testng.annotations.Test import org.testng.annotations.Test
@ -74,108 +74,106 @@ class UtilsTest {
@Test @Test
fun testBold() { fun testBold() {
Assertions.assertThat(bold(1)).`as`("bold(1)").isEqualTo(Colors.BOLD + "1" + Colors.BOLD) assertThat(bold(1)).`as`("bold(1)").isEqualTo(Colors.BOLD + "1" + Colors.BOLD)
Assertions.assertThat(bold(ascii)).`as`("bold(ascii)").isEqualTo(Colors.BOLD + ascii + Colors.BOLD) assertThat(bold(ascii)).`as`("bold(ascii)").isEqualTo(Colors.BOLD + ascii + Colors.BOLD)
} }
@Test @Test
fun testCapitalize() { fun testCapitalize() {
Assertions.assertThat(capitalize("test")).`as`("capitalize(test)").isEqualTo("Test") assertThat(capitalize("test")).`as`("capitalize(test)").isEqualTo("Test")
Assertions.assertThat(capitalize("Test")).`as`("capitalize(Test)").isEqualTo("Test") assertThat(capitalize("Test")).`as`("capitalize(Test)").isEqualTo("Test")
Assertions.assertThat(capitalize(null)).`as`("captitalize(null)").isNull() assertThat(capitalize(null)).`as`("captitalize(null)").isNull()
Assertions.assertThat(capitalize("")).`as`("capitalize()").isEqualTo("") assertThat(capitalize("")).`as`("capitalize()").isEqualTo("")
} }
@Test @Test
fun testColorize() { fun testColorize() {
Assertions.assertThat(colorize(ascii, Colors.REVERSE)).`as`("colorize(reverse)").isEqualTo( assertThat(colorize(ascii, Colors.REVERSE)).`as`("colorize(reverse)").isEqualTo(
Colors.REVERSE + ascii + Colors.REVERSE Colors.REVERSE + ascii + Colors.REVERSE
) )
Assertions.assertThat(colorize(ascii, Colors.RED)).`as`("colorize(red)") assertThat(colorize(ascii, Colors.RED)).`as`("colorize(red)").isEqualTo(Colors.RED + ascii + Colors.NORMAL)
.isEqualTo(Colors.RED + ascii + Colors.NORMAL) assertThat(colorize(null, Colors.RED)).`as`("colorize(null)").isEqualTo(Colors.NORMAL)
Assertions.assertThat(colorize(null, Colors.RED)).`as`("colorize(null)").isEqualTo(Colors.NORMAL)
} }
@Test @Test
fun testCyan() { fun testCyan() {
Assertions.assertThat(cyan(ascii)).isEqualTo(Colors.CYAN + ascii + Colors.NORMAL) assertThat(cyan(ascii)).isEqualTo(Colors.CYAN + ascii + Colors.NORMAL)
} }
@Test @Test
fun testEnsureDir() { fun testEnsureDir() {
Assertions.assertThat(ensureDir("dir", false)).`as`("ensureDir(dir, false)") assertThat(ensureDir("dir", false)).`as`("ensureDir(dir, false)").isEqualTo("dir" + File.separatorChar)
.isEqualTo("dir" + File.separatorChar) assertThat(ensureDir("https://erik.thauvin.net", true)).`as`("ensureDir(erik.thauvin.net, true)")
Assertions.assertThat(ensureDir("https://erik.thauvin.net", true)).`as`("ensureDir(erik.thauvin.net, true)")
.isEqualTo("https://erik.thauvin.net/") .isEqualTo("https://erik.thauvin.net/")
} }
@Test @Test
fun testGetIntProperty() { fun testGetIntProperty() {
Assertions.assertThat(getIntProperty("10", 1)).`as`("getIntProperty(10, 1)").isEqualTo(10) assertThat(getIntProperty("10", 1)).`as`("getIntProperty(10, 1)").isEqualTo(10)
Assertions.assertThat(getIntProperty("a", 1)).`as`("getIntProperty(a, 1)").isEqualTo(1) assertThat(getIntProperty("a", 1)).`as`("getIntProperty(a, 1)").isEqualTo(1)
} }
@Test @Test
fun testGreen() { fun testGreen() {
Assertions.assertThat(green(ascii)).isEqualTo(Colors.DARK_GREEN + ascii + Colors.NORMAL) assertThat(green(ascii)).isEqualTo(Colors.DARK_GREEN + ascii + Colors.NORMAL)
} }
@Test @Test
fun testIsoLocalDate() { fun testIsoLocalDate() {
Assertions.assertThat(isoLocalDate(cal.time)).`as`("isoLocalDate(date)").isEqualTo("1952-02-17") assertThat(isoLocalDate(cal.time)).`as`("isoLocalDate(date)").isEqualTo("1952-02-17")
Assertions.assertThat(isoLocalDate(localDateTime)).`as`("isoLocalDate(localDate)").isEqualTo("1952-02-17") assertThat(isoLocalDate(localDateTime)).`as`("isoLocalDate(localDate)").isEqualTo("1952-02-17")
} }
@Test @Test
fun testObfuscate() { fun testObfuscate() {
Assertions.assertThat(obfuscate(ascii).length).`as`("obfuscate is right length").isEqualTo(ascii.length) assertThat(obfuscate(ascii).length).`as`("obfuscate is right length").isEqualTo(ascii.length)
Assertions.assertThat(obfuscate(ascii)).`as`("obfuscate()").isEqualTo(StringUtils.repeat("x", ascii.length)) assertThat(obfuscate(ascii)).`as`("obfuscate()").isEqualTo(StringUtils.repeat("x", ascii.length))
Assertions.assertThat(obfuscate(" ")).`as`("obfuscate(blank)").isEqualTo(" ") assertThat(obfuscate(" ")).`as`("obfuscate(blank)").isEqualTo(" ")
} }
@Test @Test
fun testPlural() { fun testPlural() {
val week = "week" val week = "week"
val weeks = "weeks" val weeks = "weeks"
Assertions.assertThat(plural(-1, week, weeks)).`as`("plural(-1)").isEqualTo(week) assertThat(plural(-1, week, weeks)).`as`("plural(-1)").isEqualTo(week)
Assertions.assertThat(plural(0, week, weeks)).`as`("plural(0)").isEqualTo(week) assertThat(plural(0, week, weeks)).`as`("plural(0)").isEqualTo(week)
Assertions.assertThat(plural(1, week, weeks)).`as`("plural(1)").isEqualTo(week) assertThat(plural(1, week, weeks)).`as`("plural(1)").isEqualTo(week)
Assertions.assertThat(plural(2, week, weeks)).`as`("plural(2)").isEqualTo(weeks) assertThat(plural(2, week, weeks)).`as`("plural(2)").isEqualTo(weeks)
} }
@Test @Test
fun testReverseColor() { fun testReverseColor() {
Assertions.assertThat(reverseColor(ascii)).isEqualTo(Colors.REVERSE + ascii + Colors.REVERSE) assertThat(reverseColor(ascii)).isEqualTo(Colors.REVERSE + ascii + Colors.REVERSE)
} }
@Test @Test
fun testToday() { fun testToday() {
Assertions.assertThat(today()).isEqualTo(isoLocalDate(LocalDateTime.now())) assertThat(today()).isEqualTo(isoLocalDate(LocalDateTime.now()))
} }
@Test @Test
fun testUnescapeXml() { fun testUnescapeXml() {
Assertions.assertThat(unescapeXml("<a name="test & ''">")).isEqualTo( assertThat(unescapeXml("<a name="test & ''">")).isEqualTo(
"<a name=\"test & ''\">" "<a name=\"test & ''\">"
) )
} }
@Test @Test
fun testUptime() { fun testUptime() {
Assertions.assertThat("17 years 2 months 2 weeks 1 day 6 hours 45 minutes").isEqualTo(uptime(547800300076L)) assertThat("17 years 2 months 2 weeks 1 day 6 hours 45 minutes").isEqualTo(uptime(547800300076L))
} }
@Test @Test
@Throws(IOException::class) @Throws(IOException::class)
fun testUrlReader() { fun testUrlReader() {
Assertions.assertThat(urlReader(URL("https://postman-echo.com/status/200"))).`as`("urlReader()").isEqualTo( assertThat(urlReader(URL("https://postman-echo.com/status/200"))).`as`("urlReader()").isEqualTo(
"{\"status\":200}" "{\"status\":200}"
) )
} }
@Test @Test
fun testUtcDateTime() { fun testUtcDateTime() {
Assertions.assertThat(utcDateTime(cal.time)).`as`("utcDateTime(date)").isEqualTo("1952-02-17 12:30") assertThat(utcDateTime(cal.time)).`as`("utcDateTime(date)").isEqualTo("1952-02-17 12:30")
Assertions.assertThat(utcDateTime(localDateTime)).`as`("utcDateTime(localDate)").isEqualTo("1952-02-17 12:30") assertThat(utcDateTime(localDateTime)).`as`("utcDateTime(localDate)").isEqualTo("1952-02-17 12:30")
} }
} }

View file

@ -31,7 +31,7 @@
*/ */
package net.thauvin.erik.mobibot.commands.tell package net.thauvin.erik.mobibot.commands.tell
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test import org.testng.annotations.Test
import java.time.Duration import java.time.Duration
import java.time.LocalDateTime import java.time.LocalDateTime
@ -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)
Assertions.assertThat(tellMessage.sender).`as`(sender).isEqualTo(sender) assertThat(tellMessage.sender).`as`(sender).isEqualTo(sender)
Assertions.assertThat(tellMessage.recipient).`as`(recipient).isEqualTo(recipient) assertThat(tellMessage.recipient).`as`(recipient).isEqualTo(recipient)
Assertions.assertThat(tellMessage.message).`as`(message).isEqualTo(message) assertThat(tellMessage.message).`as`(message).isEqualTo(message)
Assertions.assertThat(isValidDate(tellMessage.queued)).`as`("queued is valid date/time").isTrue assertThat(isValidDate(tellMessage.queued)).`as`("queued is valid date/time").isTrue
Assertions.assertThat(tellMessage.isMatch(sender)).`as`("match sender").isTrue assertThat(tellMessage.isMatch(sender)).`as`("match sender").isTrue
Assertions.assertThat(tellMessage.isMatch(recipient)).`as`("match recipient").isTrue assertThat(tellMessage.isMatch(recipient)).`as`("match recipient").isTrue
Assertions.assertThat(tellMessage.isMatch("foo")).`as`("foo is no match").isFalse assertThat(tellMessage.isMatch("foo")).`as`("foo is no match").isFalse
tellMessage.isReceived = true tellMessage.isReceived = true
Assertions.assertThat(tellMessage.isReceived).`as`("is received").isTrue assertThat(tellMessage.isReceived).`as`("is received").isTrue
Assertions.assertThat(isValidDate(tellMessage.receptionDate)).`as`("received is valid date/time").isTrue assertThat(isValidDate(tellMessage.receptionDate)).`as`("received is valid date/time").isTrue
tellMessage.isNotified = true tellMessage.isNotified = true
Assertions.assertThat(tellMessage.isNotified).`as`("is notified").isTrue assertThat(tellMessage.isNotified).`as`("is notified").isTrue
} }
} }

View file

@ -32,7 +32,7 @@
package net.thauvin.erik.mobibot.entries package net.thauvin.erik.mobibot.entries
import com.rometools.rome.feed.synd.SyndCategory import com.rometools.rome.feed.synd.SyndCategory
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test import org.testng.annotations.Test
import java.security.SecureRandom import java.security.SecureRandom
@ -56,37 +56,37 @@ class EntryLinkTest {
entryLink.addComment("c$i", "u$i") entryLink.addComment("c$i", "u$i")
i++ i++
} }
Assertions.assertThat(entryLink.comments.size).`as`("getComments().size() == 5").isEqualTo(i) assertThat(entryLink.comments.size).`as`("getComments().size() == 5").isEqualTo(i)
i = 0 i = 0
for (comment in entryLink.comments) { for (comment in entryLink.comments) {
Assertions.assertThat(comment.comment).`as`("getComment($i)").isEqualTo("c$i") assertThat(comment.comment).`as`("getComment($i)").isEqualTo("c$i")
Assertions.assertThat(comment.nick).`as`("getNick($i)").isEqualTo("u$i") assertThat(comment.nick).`as`("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))
} }
Assertions.assertThat(entryLink.comments.isNotEmpty()).`as`("hasComments()").isFalse assertThat(entryLink.comments.isNotEmpty()).`as`("hasComments()").isFalse
entryLink.addComment("nothing", "nobody") entryLink.addComment("nothing", "nobody")
entryLink.setComment(0, "something", "somebody") entryLink.setComment(0, "something", "somebody")
Assertions.assertThat(entryLink.getComment(0).nick).`as`("getNick(somebody)").isEqualTo("somebody") assertThat(entryLink.getComment(0).nick).`as`("getNick(somebody)").isEqualTo("somebody")
Assertions.assertThat(entryLink.getComment(0).comment).`as`("getComment(something)").isEqualTo("something") assertThat(entryLink.getComment(0).comment).`as`("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()) {
Assertions.assertThat(tag.name).`as`("tag.getName($i)").isEqualTo("tag" + (i + 1)) assertThat(tag.name).`as`("tag.getName($i)").isEqualTo("tag" + (i + 1))
} }
Assertions.assertThat(entryLink.tags.size).`as`("getTags().size() is 5").isEqualTo(5) assertThat(entryLink.tags.size).`as`("getTags().size() is 5").isEqualTo(5)
Assertions.assertThat(entryLink.tags.isNotEmpty()).`as`("hasTags() is true").isTrue assertThat(entryLink.tags.isNotEmpty()).`as`("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")
Assertions.assertThat(entryLink.pinboardTags).`as`("getPinboardTags()") assertThat(entryLink.pinboardTags).`as`("getPinboardTags()")
.isEqualTo(entryLink.nick + ",tag1,tag2,tag3,tag4,mobitopia") .isEqualTo(entryLink.nick + ",tag1,tag2,tag3,tag4,mobitopia")
} }
} }

View file

@ -33,7 +33,7 @@ package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.Utils import net.thauvin.erik.mobibot.Utils
import net.thauvin.erik.mobibot.modules.Calc.Companion.calc import net.thauvin.erik.mobibot.modules.Calc.Companion.calc
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test import org.testng.annotations.Test
/** /**
@ -42,13 +42,9 @@ import org.testng.annotations.Test
class CalcTest { class CalcTest {
@Test @Test
fun testCalc() { fun testCalc() {
Assertions.assertThat(calc("1 + 1")).`as`("calc(1+1)") assertThat(calc("1 + 1")).`as`("calc(1+1)").isEqualTo("1+1 = %s", Utils.bold(2))
.isEqualTo("1+1 = %s", Utils.bold(2)) assertThat(calc("1 -3")).`as`("calc(1 -3)").isEqualTo("1-3 = %s", Utils.bold(-2))
Assertions.assertThat(calc("1 -3")).`as`("calc(1 -3)") assertThat(calc("pi+π+e+φ")).`as`("calc(pi+π+e+φ)").isEqualTo("pi+π+e+φ = %s", Utils.bold("10.62"))
.isEqualTo("1-3 = %s", Utils.bold(-2)) assertThat(calc("one + one")).`as`("calc(one + one)").startsWith("No idea.")
Assertions.assertThat(calc("pi+π+e+φ")).`as`("calc(pi+π+e+φ)")
.isEqualTo("pi+π+e+φ = %s", Utils.bold("10.62"))
Assertions.assertThat(calc("one + one")).`as`("calc(one + one)")
.startsWith("No idea.")
} }
} }

View file

@ -34,7 +34,7 @@ package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.convertCurrency import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.convertCurrency
import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.currencyRates import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.currencyRates
import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.loadRates import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.loadRates
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.BeforeClass import org.testng.annotations.BeforeClass
import org.testng.annotations.Test import org.testng.annotations.Test
@ -50,15 +50,11 @@ class CurrencyConverterTest {
@Test @Test
fun testConvertCurrency() { fun testConvertCurrency() {
Assertions.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") .`as`("100 USD to EUR").matches("100\\.00 USD = \\d{2,3}\\.\\d{2} EUR")
Assertions.assertThat(convertCurrency("100 USD to USD").msg) assertThat(convertCurrency("100 USD to USD").msg).`as`("100 USD to USD").contains("You're kidding, right?")
.`as`("100 USD to USD").contains("You're kidding, right?") assertThat(convertCurrency("100 USD").msg).`as`("100 USD").contains("Invalid query.")
Assertions.assertThat(convertCurrency("100 USD").msg) assertThat(currencyRates().size).`as`("currencyRates().size() == 33").isEqualTo(33)
.`as`("100 USD").contains("Invalid query.") assertThat(currencyRates()).`as`("currencyRates().get(EUR)").contains(" EUR: 1")
Assertions.assertThat(currencyRates().size)
.`as`("currencyRates().size() == 33").isEqualTo(33)
Assertions.assertThat(currencyRates())
.`as`("currencyRates().get(EUR)").contains(" EUR: 1")
} }
} }

View file

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

View file

@ -33,7 +33,8 @@ package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.LocalProperties import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.GoogleSearch.Companion.searchGoogle import net.thauvin.erik.mobibot.modules.GoogleSearch.Companion.searchGoogle
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.testng.annotations.Test import org.testng.annotations.Test
/** /**
@ -47,18 +48,18 @@ class GoogleSearchTest : LocalProperties() {
val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP) val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP)
try { try {
var messages = searchGoogle("mobibot site:github.com", apiKey, cseKey) var messages = searchGoogle("mobibot site:github.com", apiKey, cseKey)
Assertions.assertThat(messages).`as`("mobibot results not empty").isNotEmpty assertThat(messages).`as`("mobibot results not empty").isNotEmpty
Assertions.assertThat(messages[0].msg).`as`("found mobitopia").contains("mobibot") assertThat(messages[0].msg).`as`("found mobitopia").contains("mobibot")
messages = searchGoogle("aapl", apiKey, cseKey) messages = searchGoogle("aapl", apiKey, cseKey)
Assertions.assertThat(messages).`as`("aapl results not empty").isNotEmpty assertThat(messages).`as`("aapl results not empty").isNotEmpty
Assertions.assertThat(messages[0].msg).`as`("found apple").containsIgnoringCase("apple") assertThat(messages[0].msg).`as`("found apple").containsIgnoringCase("apple")
Assertions.assertThatThrownBy { searchGoogle("test", "", "apiKey") } assertThatThrownBy { searchGoogle("test", "", "apiKey") }
.`as`("no API key") .`as`("no API key")
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java).hasNoCause()
Assertions.assertThatThrownBy { searchGoogle("test", "apiKey", "") } assertThatThrownBy { searchGoogle("test", "apiKey", "") }
.`as`("no CSE API key") .`as`("no CSE API key")
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java).hasNoCause()
Assertions.assertThatThrownBy { searchGoogle("", "apikey", "apiKey") } assertThatThrownBy { searchGoogle("", "apikey", "apiKey") }
.`as`("no query").isInstanceOf(ModuleException::class.java).hasNoCause() .`as`("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

View file

@ -32,7 +32,7 @@
package net.thauvin.erik.mobibot.modules package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.modules.Joke.Companion.randomJoke import net.thauvin.erik.mobibot.modules.Joke.Companion.randomJoke
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test import org.testng.annotations.Test
/** /**
@ -42,7 +42,7 @@ class JokeTest {
@Test @Test
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun testRamdomJoke() { fun testRamdomJoke() {
Assertions.assertThat(randomJoke().msg.isNotEmpty()).`as`("randomJoke() > 0").isTrue assertThat(randomJoke().msg.isNotEmpty()).`as`("randomJoke() > 0").isTrue
Assertions.assertThat(randomJoke().msg).`as`("randomJoke()").containsIgnoringCase("chuck") assertThat(randomJoke().msg).`as`("randomJoke()").containsIgnoringCase("chuck")
} }
} }

View file

@ -33,7 +33,7 @@ package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.modules.Lookup.Companion.lookup import net.thauvin.erik.mobibot.modules.Lookup.Companion.lookup
import net.thauvin.erik.mobibot.modules.Lookup.Companion.whois import net.thauvin.erik.mobibot.modules.Lookup.Companion.whois
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test import org.testng.annotations.Test
/** /**
@ -44,14 +44,14 @@ class LookupTest {
@Throws(Exception::class) @Throws(Exception::class)
fun testLookup() { fun testLookup() {
val result = lookup("apple.com") val result = lookup("apple.com")
Assertions.assertThat(result).`as`("lookup(apple.com)").contains("17.253.144.10") assertThat(result).`as`("lookup(apple.com)").contains("17.253.144.10")
} }
@Test @Test
@Throws(Exception::class) @Throws(Exception::class)
fun testWhois() { fun testWhois() {
val result = whois("17.178.96.59", Lookup.WHOIS_HOST) val result = whois("17.178.96.59", Lookup.WHOIS_HOST)
Assertions.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 .`as`("whois(17.178.96.59/Apple Inc.").isTrue
} }
} }

View file

@ -32,7 +32,7 @@
package net.thauvin.erik.mobibot.modules package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.modules.Ping.Companion.randomPing import net.thauvin.erik.mobibot.modules.Ping.Companion.randomPing
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test import org.testng.annotations.Test
/** /**
@ -41,13 +41,13 @@ import org.testng.annotations.Test
class PingTest { class PingTest {
@Test @Test
fun testPingsArray() { fun testPingsArray() {
Assertions.assertThat(Ping.PINGS).`as`("Pings array is not empty.").isNotEmpty assertThat(Ping.PINGS).`as`("Pings array is not empty.").isNotEmpty
} }
@Test @Test
fun testRandomPing() { fun testRandomPing() {
for (i in 0..9) { for (i in 0..9) {
Assertions.assertThat(randomPing()).`as`("Random ping $i").isIn(Ping.PINGS) assertThat(randomPing()).`as`("Random ping $i").isIn(Ping.PINGS)
} }
} }
} }

View file

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

View file

@ -33,7 +33,8 @@ package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.LocalProperties import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.StockQuote.Companion.getQuote import net.thauvin.erik.mobibot.modules.StockQuote.Companion.getQuote
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.testng.annotations.Test import org.testng.annotations.Test
/** /**
@ -46,20 +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)
Assertions.assertThat(messages).`as`("response not empty").isNotEmpty assertThat(messages).`as`("response not empty").isNotEmpty
Assertions.assertThat(messages[0].msg).`as`("same stock symbol") assertThat(messages[0].msg).`as`("same stock symbol").startsWith("Symbol: AAPL")
.startsWith("Symbol: AAPL") assertThat(messages[1].msg).`as`("price label").startsWith(" Price: ")
Assertions.assertThat(messages[1].msg).`as`("price label")
.startsWith(" Price: ")
try { try {
getQuote("blahfoo", apiKey) getQuote("blahfoo", apiKey)
} catch (e: ModuleException) { } catch (e: ModuleException) {
Assertions.assertThat(e.message).`as`("invalid symbol") assertThat(e.message).`as`("invalid symbol").containsIgnoringCase(StockQuote.INVALID_SYMBOL)
.containsIgnoringCase(StockQuote.INVALID_SYMBOL)
} }
Assertions.assertThatThrownBy { getQuote("test", "") }.`as`("no API key") assertThatThrownBy { getQuote("test", "") }.`as`("no API key")
.isInstanceOf(ModuleException::class.java).hasNoCause() .isInstanceOf(ModuleException::class.java).hasNoCause()
Assertions.assertThatThrownBy { getQuote("", "apikey") }.`as`("no symbol") assertThatThrownBy { getQuote("", "apikey") }.`as`("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

@ -33,7 +33,7 @@ package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.LocalProperties import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.Twitter.Companion.twitterPost import net.thauvin.erik.mobibot.modules.Twitter.Companion.twitterPost
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test import org.testng.annotations.Test
import java.net.InetAddress import java.net.InetAddress
import java.net.UnknownHostException import java.net.UnknownHostException
@ -56,7 +56,7 @@ class TwitterTest : LocalProperties() {
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun testPostTwitter() { fun testPostTwitter() {
val msg = "Testing Twitter API from $ci" val msg = "Testing Twitter API from $ci"
Assertions.assertThat( assertThat(
twitterPost( twitterPost(
getProperty(Twitter.CONSUMER_KEY_PROP), getProperty(Twitter.CONSUMER_KEY_PROP),
getProperty(Twitter.CONSUMER_SECRET_PROP), getProperty(Twitter.CONSUMER_SECRET_PROP),

View file

@ -34,7 +34,8 @@ package net.thauvin.erik.mobibot.modules
import net.aksingh.owmjapis.api.APIException import net.aksingh.owmjapis.api.APIException
import net.thauvin.erik.mobibot.LocalProperties import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.Weather2.Companion.getWeather import net.thauvin.erik.mobibot.modules.Weather2.Companion.getWeather
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.testng.annotations.Test import org.testng.annotations.Test
/** /**
@ -45,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))
Assertions.assertThat(messages[0].msg).`as`("is Everett").contains("Everett").contains("US") assertThat(messages[0].msg).`as`("is Everett").contains("Everett").contains("US")
Assertions.assertThat(messages[messages.size - 1].msg).`as`("is City Search").endsWith("98204%2CUS") assertThat(messages[messages.size - 1].msg).`as`("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))
Assertions.assertThat(messages[0].msg).`as`("is UK").contains("London").contains("UK") assertThat(messages[0].msg).`as`("is UK").contains("London").contains("UK")
Assertions.assertThat(messages[messages.size - 1].msg).`as`("is City Code").endsWith("4517009") assertThat(messages[messages.size - 1].msg).`as`("is City Code").endsWith("4517009")
Assertions.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) .`as`("Montpellier not found").hasCauseInstanceOf(APIException::class.java)
Assertions.assertThatThrownBy { getWeather("test", "") } assertThatThrownBy { getWeather("test", "") }
.`as`("no API key").isInstanceOf(ModuleException::class.java).hasNoCause() .`as`("no API key").isInstanceOf(ModuleException::class.java).hasNoCause()
messages = getWeather("", "apikey") messages = getWeather("", "apikey")
Assertions.assertThat(messages[0].isError).`as`("no query").isTrue assertThat(messages[0].isError).`as`("no query").isTrue
} }
} }

View file

@ -33,7 +33,7 @@ package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.Utils import net.thauvin.erik.mobibot.Utils
import net.thauvin.erik.mobibot.modules.WorldTime.Companion.worldTime import net.thauvin.erik.mobibot.modules.WorldTime.Companion.worldTime
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test import org.testng.annotations.Test
/** /**
@ -42,8 +42,8 @@ import org.testng.annotations.Test
class WordTimeTest { class WordTimeTest {
@Test @Test
fun testWorldTime() { fun testWorldTime() {
Assertions.assertThat(worldTime("PST").msg).`as`("PST").endsWith(Utils.bold("Los Angeles")) assertThat(worldTime("PST").msg).`as`("PST").endsWith(Utils.bold("Los Angeles"))
Assertions.assertThat(worldTime("BLAH").isError).`as`("BLAH").isTrue assertThat(worldTime("BLAH").isError).`as`("BLAH").isTrue
Assertions.assertThat(worldTime("BEATS").msg).`as`("BEATS").contains("@") assertThat(worldTime("BEATS").msg).`as`("BEATS").contains("@")
} }
} }

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle #Generated by the Semver Plugin for Gradle
#Tue Apr 27 17:59:17 PDT 2021 #Wed Apr 28 08:21:37 PDT 2021
version.buildmeta=487 version.buildmeta=494
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+487 version.semver=0.8.0-beta+494