Cleaned up tests
This commit is contained in:
parent
9bb7b34c69
commit
acf56b2178
9 changed files with 47 additions and 47 deletions
|
@ -60,21 +60,21 @@ class CurrencyConverterTest {
|
||||||
fun testConvertCurrency() {
|
fun testConvertCurrency() {
|
||||||
assertThat(
|
assertThat(
|
||||||
convertCurrency("100 USD to EUR").msg,
|
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())
|
).matches("100 United States Dollar = \\d{2,3}\\.\\d+ Euro".toRegex())
|
||||||
assertThat(
|
assertThat(
|
||||||
convertCurrency("1 USD to BTC").msg,
|
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())
|
).matches("1 United States Dollar = 0\\.\\d+ Bitcoin".toRegex())
|
||||||
assertThat(
|
assertThat(
|
||||||
convertCurrency("100,000.00 GBP to BTC").msg,
|
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())
|
).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?")
|
prop(Message::msg).contains("You're kidding, right?")
|
||||||
isInstanceOf(PublicMessage::class.java)
|
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.")
|
prop(Message::msg).contains("Invalid query.")
|
||||||
isInstanceOf(ErrorMessage::class.java)
|
isInstanceOf(ErrorMessage::class.java)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,14 +41,14 @@ import org.testng.annotations.Test
|
||||||
class DiceTest {
|
class DiceTest {
|
||||||
@Test(groups = ["modules"])
|
@Test(groups = ["modules"])
|
||||||
fun testRoll() {
|
fun testRoll() {
|
||||||
assertThat(Dice.roll(1, 1), "1d1").isEqualTo("\u00021\u0002")
|
assertThat(Dice.roll(1, 1), "1d1 is invalid").isEqualTo("\u00021\u0002")
|
||||||
assertThat(Dice.roll(2, 1), "2d1")
|
assertThat(Dice.roll(2, 1), "2d1 is invalid")
|
||||||
.isEqualTo("\u00021\u0002 + \u00021\u0002 = \u00022\u0002")
|
.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")
|
.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())
|
.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())
|
.matches("\u0002[1-7]\u0002 \\+ \u0002[1-7]\u0002 \\+ \u0002[1-7]\u0002 = \u0002\\d{1,2}\u0002".toRegex())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,8 @@ class GoogleSearchTest : LocalProperties() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var messages = searchGoogle("mobibot", apiKey, cseKey)
|
var messages = searchGoogle("mobibot", apiKey, cseKey)
|
||||||
assertThat(messages, "mobibot results not empty").isNotEmpty()
|
assertThat(messages, "search result should not be empty").isNotEmpty()
|
||||||
assertThat(messages[0].msg, "found mobibot").contains("mobibot", true)
|
assertThat(messages[0].msg, "search query not found").contains("mobibot", true)
|
||||||
|
|
||||||
messages = searchGoogle("adadflkjl", apiKey, cseKey)
|
messages = searchGoogle("adadflkjl", apiKey, cseKey)
|
||||||
assertThat(messages[0], "not found").all {
|
assertThat(messages[0], "not found").all {
|
||||||
|
|
|
@ -66,41 +66,41 @@ class ModuleExceptionTest {
|
||||||
|
|
||||||
@Test(dataProvider = "dp")
|
@Test(dataProvider = "dp")
|
||||||
fun testGetDebugMessage(e: ModuleException) {
|
fun testGetDebugMessage(e: ModuleException) {
|
||||||
assertThat(e.debugMessage, "get debug message").isEqualTo(debugMessage)
|
assertThat(e.debugMessage, "debug message is invalid").isEqualTo(debugMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "dp")
|
@Test(dataProvider = "dp")
|
||||||
fun testGetMessage(e: ModuleException) {
|
fun testGetMessage(e: ModuleException) {
|
||||||
assertThat(e, "get message").hasMessage(message)
|
assertThat(e, "message is invalid").hasMessage(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = ["modules"])
|
@Test(groups = ["modules"])
|
||||||
fun testSanitizeMessage() {
|
fun testSanitizeMessage() {
|
||||||
val apiKey = "1234567890"
|
val apiKey = "1234567890"
|
||||||
var e = ModuleException(debugMessage, message, IOException("URL http://foo.com?apiKey=$apiKey&userID=me"))
|
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")
|
contains("xxxxxxxxxx", "userID=xx", "java.io.IOException")
|
||||||
doesNotContain(apiKey, "me")
|
doesNotContain(apiKey, "me")
|
||||||
}
|
}
|
||||||
|
|
||||||
e = ModuleException(debugMessage, message, null)
|
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())
|
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)
|
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
|
val msg: String? = null
|
||||||
e = ModuleException(debugMessage, msg, IOException(msg))
|
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"))
|
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)
|
doesNotContain(apiKey)
|
||||||
endsWith("xxx is xxxxxxxxxx")
|
endsWith("xxx is xxxxxxxxxx")
|
||||||
}
|
}
|
||||||
assertThat(e.sanitize(), "empty").isEqualTo(e)
|
assertThat(e.sanitize(), "exception should be unchanged").isEqualTo(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.testng.annotations.Test
|
||||||
class PingTest {
|
class PingTest {
|
||||||
@Test(groups = ["modules"])
|
@Test(groups = ["modules"])
|
||||||
fun testPingsArray() {
|
fun testPingsArray() {
|
||||||
assertThat(Ping.PINGS, "Pings array is not empty.").isNotEmpty()
|
assertThat(Ping.PINGS, "Pings array should be empty").isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = ["modules"])
|
@Test(groups = ["modules"])
|
||||||
|
|
|
@ -62,16 +62,16 @@ class StockQuoteTest : LocalProperties() {
|
||||||
try {
|
try {
|
||||||
val messages = getQuote("apple inc", apiKey)
|
val messages = getQuote("apple inc", apiKey)
|
||||||
assertThat(messages, "response not empty").isNotEmpty()
|
assertThat(messages, "response not empty").isNotEmpty()
|
||||||
assertThat(messages[0].msg, "same stock symbol").matches("Symbol: AAPL .*".toRegex())
|
assertThat(messages[0].msg, "stock symbol should be AAPL").matches("Symbol: AAPL .*".toRegex())
|
||||||
assertThat(messages[1].msg, "price label").matches(buildMatch("Price").toRegex())
|
assertThat(messages[1].msg, "price label is invalid").matches(buildMatch("Price").toRegex())
|
||||||
assertThat(messages[2].msg, "previous label").matches(buildMatch("Previous").toRegex())
|
assertThat(messages[2].msg, "previous label is invalid").matches(buildMatch("Previous").toRegex())
|
||||||
assertThat(messages[3].msg, "open label").matches(buildMatch("Open").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)
|
isInstanceOf(ErrorMessage::class.java)
|
||||||
prop(Message::msg).isEqualTo(StockQuote.INVALID_SYMBOL)
|
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)
|
isInstanceOf(ErrorMessage::class.java)
|
||||||
prop(Message::msg).isEqualTo(StockQuote.INVALID_SYMBOL)
|
prop(Message::msg).isEqualTo(StockQuote.INVALID_SYMBOL)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,8 @@ class Weather2Test : LocalProperties() {
|
||||||
|
|
||||||
@Test(groups = ["modules"])
|
@Test(groups = ["modules"])
|
||||||
fun testGetCountry() {
|
fun testGetCountry() {
|
||||||
assertThat(getCountry("foo"), "not a country").isEqualTo(OWM.Country.UNITED_STATES)
|
assertThat(getCountry("foo"), "foo is not a valid country").isEqualTo(OWM.Country.UNITED_STATES)
|
||||||
assertThat(getCountry("fr"), "fr is france").isEqualTo(OWM.Country.FRANCE)
|
assertThat(getCountry("fr"), "country should France").isEqualTo(OWM.Country.FRANCE)
|
||||||
|
|
||||||
val country = OWM.Country.values()
|
val country = OWM.Country.values()
|
||||||
repeat(3) {
|
repeat(3) {
|
||||||
|
@ -83,30 +83,30 @@ class Weather2Test : LocalProperties() {
|
||||||
@Throws(ModuleException::class)
|
@Throws(ModuleException::class)
|
||||||
fun testWeather() {
|
fun testWeather() {
|
||||||
var messages = getWeather("98204", getProperty(OWM_API_KEY_PROP))
|
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("Everett, United States")
|
||||||
contains("US")
|
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))
|
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("San Francisco")
|
||||||
contains("US")
|
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))
|
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("London, United Kingdom")
|
||||||
contains("GB")
|
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 {
|
try {
|
||||||
getWeather("Foo, US", getProperty(OWM_API_KEY_PROP))
|
getWeather("Foo, US", getProperty(OWM_API_KEY_PROP))
|
||||||
} catch (e: ModuleException) {
|
} 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()
|
assertThat { getWeather("test", "") }.isFailure()
|
||||||
|
@ -115,6 +115,6 @@ class Weather2Test : LocalProperties() {
|
||||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||||
|
|
||||||
messages = getWeather("", "apikey")
|
messages = getWeather("", "apikey")
|
||||||
assertThat(messages[0].isError, "no query").isTrue()
|
assertThat(messages[0].isError, "empty query should be an error").isTrue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,12 +55,12 @@ class WordTimeTest {
|
||||||
"on ${Colors.BOLD}\\w+, \\d{1,2} \\w+ \\d{4}${Colors.BOLD} " +
|
"on ${Colors.BOLD}\\w+, \\d{1,2} \\w+ \\d{4}${Colors.BOLD} " +
|
||||||
"in ${Colors.BOLD}Los Angeles${Colors.BOLD}").toRegex()
|
"in ${Colors.BOLD}Los Angeles${Colors.BOLD}").toRegex()
|
||||||
)
|
)
|
||||||
assertThat(time(""), "empty zone").endsWith("Los Angeles".bold())
|
assertThat(time(""), "zone is not LA").endsWith("Los Angeles".bold())
|
||||||
assertThat(time("PST"), "PST").endsWith("Los Angeles".bold())
|
assertThat(time("PST"), "zone is not PST").endsWith("Los Angeles".bold())
|
||||||
assertThat(time("GB"), "GB").endsWith("London".bold())
|
assertThat(time("GB"), "zone is not London").endsWith("London".bold())
|
||||||
assertThat(time("FR"), "FR").endsWith("Paris".bold())
|
assertThat(time("FR"), "zone is not Paris").endsWith("Paris".bold())
|
||||||
assertThat(time("BLAH"), "BLAH").startsWith("Unsupported")
|
assertThat(time("BLAH"), "zone should be unsupported").startsWith("Unsupported")
|
||||||
assertThat(time("BEAT"), BEATS_KEYWORD).matches("[\\w ]+ .?@\\d{3}+.? .beats".toRegex())
|
assertThat(time("BEAT"), "$BEATS_KEYWORD is invalid").matches("[\\w ]+ .?@\\d{3}+.? .beats".toRegex())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = ["modules"])
|
@Test(groups = ["modules"])
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#Generated by the Semver Plugin for Gradle
|
#Generated by the Semver Plugin for Gradle
|
||||||
#Mon Sep 19 01:34:05 PDT 2022
|
#Sat Sep 24 10:52:55 PDT 2022
|
||||||
version.buildmeta=667
|
version.buildmeta=676
|
||||||
version.major=0
|
version.major=0
|
||||||
version.minor=8
|
version.minor=8
|
||||||
version.patch=0
|
version.patch=0
|
||||||
version.prerelease=rc
|
version.prerelease=rc
|
||||||
version.project=mobibot
|
version.project=mobibot
|
||||||
version.semver=0.8.0-rc+667
|
version.semver=0.8.0-rc+676
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue