Cleaned up tests.

This commit is contained in:
Erik C. Thauvin 2021-10-25 23:41:52 -07:00
parent 611420757a
commit 2a46761dc5
9 changed files with 29 additions and 31 deletions

View file

@ -51,9 +51,8 @@ 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).describedAs(sender).isEqualTo(sender) assertThat(tellMessage).extracting("sender", "recipient", "message")
assertThat(tellMessage.recipient).describedAs(recipient).isEqualTo(recipient) .containsExactly(sender, recipient, message)
assertThat(tellMessage.message).describedAs(message).isEqualTo(message)
assertThat(isValidDate(tellMessage.queued)).describedAs("queued is valid date/time").isTrue assertThat(isValidDate(tellMessage.queued)).describedAs("queued is valid date/time").isTrue
assertThat(tellMessage.isMatch(sender)).describedAs("match sender").isTrue assertThat(tellMessage.isMatch(sender)).describedAs("match sender").isTrue
assertThat(tellMessage.isMatch(recipient)).describedAs("match recipient").isTrue assertThat(tellMessage.isMatch(recipient)).describedAs("match recipient").isTrue

View file

@ -61,19 +61,18 @@ class EntryLinkTest {
assertThat(entryLink.comments.size).describedAs("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).describedAs("getComment($i)").isEqualTo("c$i") assertThat(comment).extracting("comment", "nick").containsExactly("c$i", "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()).describedAs("hasComments()").isFalse assertThat(entryLink.comments).describedAs("hasComments()").isEmpty()
entryLink.addComment("nothing", "nobody") entryLink.addComment("nothing", "nobody")
entryLink.setComment(0, "something", "somebody") entryLink.setComment(0, "something", "somebody")
assertThat(entryLink.getComment(0).nick).describedAs("getNick(somebody)").isEqualTo("somebody") assertThat(entryLink.getComment(0)).describedAs("get first comment").extracting("nick", "comment")
assertThat(entryLink.getComment(0).comment).describedAs("getComment(something)").isEqualTo("something") .containsExactly("somebody", "something")
} }
@Test @Test
@ -104,7 +103,7 @@ class EntryLinkTest {
assertThat(tag.name).describedAs("tag.getName($i)").isEqualTo("tag" + (i + 1)) assertThat(tag.name).describedAs("tag.getName($i)").isEqualTo("tag" + (i + 1))
} }
assertThat(entryLink.tags.size).describedAs("getTags().size() is 5").isEqualTo(5) assertThat(entryLink.tags.size).describedAs("getTags().size() is 5").isEqualTo(5)
assertThat(entryLink.tags.isNotEmpty()).describedAs("hasTags() is true").isTrue assertThat(entryLink.tags).describedAs("hasTags() is true").isNotEmpty
entryLink.setTags("-tag5") entryLink.setTags("-tag5")
entryLink.setTags("+mobitopia") entryLink.setTags("+mobitopia")
entryLink.setTags("tag4") entryLink.setTags("tag4")

View file

@ -43,13 +43,11 @@ class CryptoPricesTest {
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun testMarketPrice() { fun testMarketPrice() {
var price = currentPrice(listOf("BTC")) var price = currentPrice(listOf("BTC"))
assertThat(price.base).describedAs("is BTC").isEqualTo("BTC") assertThat(price).extracting("base", "currency").containsExactly("BTC", "USD")
assertThat(price.currency).describedAs("is USD").isEqualTo("USD") assertThat(price.amount.signum()).describedAs("BTC > 0").isGreaterThan(0)
assertThat(price.amount.signum() > 0).describedAs("BTC > 0").isTrue
price = currentPrice(listOf("ETH", "EUR")) price = currentPrice(listOf("ETH", "EUR"))
assertThat(price.base).describedAs("is ETH").isEqualTo("ETH") assertThat(price).extracting("base", "currency").containsExactly("ETH", "EUR")
assertThat(price.currency).describedAs("is EUR").isEqualTo("EUR") assertThat(price.amount.signum()).describedAs("ETH > 0").isGreaterThan(0)
assertThat(price.amount.signum() > 0).describedAs("ETH > 0").isTrue
} }
} }

View file

@ -57,8 +57,7 @@ class CurrencyConverterTest {
assertThat(convertCurrency("100 USD").msg).describedAs("100 USD").contains("Invalid query.") assertThat(convertCurrency("100 USD").msg).describedAs("100 USD").contains("Invalid query.")
val rates = currencyRates() val rates = currencyRates()
assertThat(rates.size).describedAs("currencyRates.size == 33").isEqualTo(33) assertThat(rates.size).describedAs("currencyRates.size == 33").isEqualTo(33)
assertThat(rates).describedAs("currencyRates(EUR)").contains("EUR: 1") assertThat(rates).describedAs("currencyRates(EUR< USD)").contains("EUR: 1")
assertThat(rates.stream().anyMatch { it.matches("USD: .*".toRegex()) }) .anyMatch { it.matches("USD: .*".toRegex()) }
.describedAs("currencyRates(USD)").isTrue
} }
} }

View file

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

View file

@ -51,7 +51,7 @@ class LookupTest {
@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)
assertThat(result.stream().anyMatch { m: String -> m.contains("Apple Inc.") }) assertThat(result).describedAs("whois(17.178.96.59/Apple Inc.")
.describedAs("whois(17.178.96.59/Apple Inc.").isTrue .anyMatch { it.contains("Apple Inc.") }
} }
} }

View file

@ -71,7 +71,8 @@ class ModuleExceptionTest {
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(sanitizeException(e, apiKey, "", "me")).describedAs("sanitized url") assertThat(sanitizeException(e, apiKey, "", "me")).describedAs("sanitized url")
.hasMessageContainingAll("xxxxxxxxxx", "userID=xx").hasMessageNotContainingAny(apiKey, "me") .hasMessageContainingAll("xxxxxxxxxx", "userID=xx", "java.io.IOException")
.hasMessageNotContainingAny(apiKey, "me")
e = ModuleException(debugMessage, message, null) e = ModuleException(debugMessage, message, null)
assertThat(sanitizeException(e, apiKey)).describedAs("no cause").hasMessage(message) assertThat(sanitizeException(e, apiKey)).describedAs("no cause").hasMessage(message)

View file

@ -42,6 +42,10 @@ import org.testng.annotations.Test
* The `StockQuoteTest` class. * The `StockQuoteTest` class.
*/ */
class StockQuoteTest : LocalProperties() { class StockQuoteTest : LocalProperties() {
private fun buildMatch(label: String): String {
return "${label}:[ ]+[0-9.]+".prependIndent()
}
@Test @Test
@Throws(ModuleException::class) @Throws(ModuleException::class)
fun testGetQuote() { fun testGetQuote() {
@ -49,10 +53,10 @@ class StockQuoteTest : LocalProperties() {
try { try {
val messages = getQuote("apple inc", apiKey) val messages = getQuote("apple inc", apiKey)
assertThat(messages).describedAs("response not empty").isNotEmpty assertThat(messages).describedAs("response not empty").isNotEmpty
assertThat(messages[0].msg).describedAs("same stock symbol").startsWith("Symbol: AAPL") assertThat(messages[0].msg).describedAs("same stock symbol").matches("Symbol: AAPL .*")
assertThat(messages[1].msg).describedAs("price label").startsWith("Price: ".prependIndent()) assertThat(messages[1].msg).describedAs("price label").matches(buildMatch("Price"))
assertThat(messages[2].msg).describedAs("previous label").startsWith("Previous: ".prependIndent()) assertThat(messages[2].msg).describedAs("previous label").matches(buildMatch("Previous"))
assertThat(messages[3].msg).describedAs("open label").startsWith("Open: ".prependIndent()) assertThat(messages[3].msg).describedAs("open label").matches(buildMatch("Open"))
try { try {
getQuote("blahfoo", apiKey) getQuote("blahfoo", apiKey)
} catch (e: ModuleException) { } catch (e: ModuleException) {

View file

@ -48,16 +48,14 @@ class WordTimeTest {
fun testTime() { fun testTime() {
assertThat(time("PST").msg).describedAs("PST").endsWith(bold("Los Angeles")) assertThat(time("PST").msg).describedAs("PST").endsWith(bold("Los Angeles"))
assertThat(time("BLAH").isError).describedAs("BLAH").isTrue assertThat(time("BLAH").isError).describedAs("BLAH").isTrue
assertThat(time("BEAT").msg).describedAs(BEATS_KEYWORD).endsWith(BEATS_KEYWORD).contains("@") assertThat(time("BEAT").msg).describedAs(BEATS_KEYWORD).matches("[\\w ]+: .?@\\d{3}+.? .beats")
} }
@Test @Test
@Throws(ZoneRulesException::class) @Throws(ZoneRulesException::class)
fun testCountries() { fun testCountries() {
COUNTRIES_MAP.toSortedMap().forEach { COUNTRIES_MAP.filter { it.value != BEATS_KEYWORD }.forEach {
if (it.value != BEATS_KEYWORD) { ZoneId.of(it.value)
ZoneId.of(it.value)
}
} }
} }
} }