Compare commits

...

3 commits

Author SHA1 Message Date
1cd7c5a79e Upgraded to Kotlin 1.9.20 2023-11-01 22:10:50 -07:00
4c90870f4a Cleaned up code 2023-11-01 22:02:54 -07:00
d700aa06df Fixed SonarCloud code smells 2023-10-26 21:13:46 -07:00
66 changed files with 555 additions and 536 deletions

2
.idea/kotlinc.xml generated
View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.10" /> <option name="version" value="1.9.20" />
</component> </component>
</project> </project>

1
.idea/misc.xml generated
View file

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">

View file

@ -7,11 +7,11 @@ plugins {
id 'application' id 'application'
id 'com.github.ben-manes.versions' version '0.49.0' id 'com.github.ben-manes.versions' version '0.49.0'
id 'idea' id 'idea'
id 'io.gitlab.arturbosch.detekt' version '1.23.1' id 'io.gitlab.arturbosch.detekt' version '1.23.3'
id 'java' id 'java'
id 'net.thauvin.erik.gradle.semver' version '1.0.4' id 'net.thauvin.erik.gradle.semver' version '1.0.4'
id 'org.jetbrains.kotlin.jvm' version '1.9.10' id 'org.jetbrains.kotlin.jvm' version '1.9.20'
id 'org.jetbrains.kotlin.kapt' version '1.9.10' id 'org.jetbrains.kotlin.kapt' version '1.9.20'
id 'org.jetbrains.kotlinx.kover' version '0.7.4' id 'org.jetbrains.kotlinx.kover' version '0.7.4'
id 'org.sonarqube' version '4.4.1.3373' id 'org.sonarqube' version '4.4.1.3373'
id 'pmd' id 'pmd'
@ -55,7 +55,7 @@ dependencies {
// Commons (mostly for PircBotX) // Commons (mostly for PircBotX)
implementation 'org.apache.commons:commons-lang3:3.13.0' implementation 'org.apache.commons:commons-lang3:3.13.0'
implementation 'org.apache.commons:commons-text:1.10.0' implementation 'org.apache.commons:commons-text:1.11.0'
implementation 'commons-codec:commons-codec:1.16.0' implementation 'commons-codec:commons-codec:1.16.0'
implementation 'commons-net:commons-net:3.10.0' implementation 'commons-net:commons-net:3.10.0'

View file

@ -2,9 +2,9 @@
<SmellBaseline> <SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues> <ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues> <CurrentIssues>
<ID>CyclomaticComplexMethod:FeedsManager.kt$FeedsManager.Companion$@JvmStatic fun saveFeed(entries: Entries, currentFile: String = currentXml)</ID> <ID>CyclomaticComplexMethod:FeedsManager.kt$FeedsManager.Companion$@JvmStatic fun saveFeed(entries: Entries, currentFile: String = CURRENT_XML)</ID>
<ID>CyclomaticComplexMethod:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List&lt;Message&gt;</ID> <ID>CyclomaticComplexMethod:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List&lt;Message&gt;</ID>
<ID>LongMethod:FeedsManager.kt$FeedsManager.Companion$@JvmStatic fun saveFeed(entries: Entries, currentFile: String = currentXml)</ID> <ID>LongMethod:FeedsManager.kt$FeedsManager.Companion$@JvmStatic fun saveFeed(entries: Entries, currentFile: String = CURRENT_XML)</ID>
<ID>LongMethod:Mobibot.kt$Mobibot.Companion$@JvmStatic @Throws(Exception::class) fun main(args: Array&lt;String&gt;)</ID> <ID>LongMethod:Mobibot.kt$Mobibot.Companion$@JvmStatic @Throws(Exception::class) fun main(args: Array&lt;String&gt;)</ID>
<ID>LongMethod:StockQuote.kt$StockQuote.Companion$@JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List&lt;Message&gt;</ID> <ID>LongMethod:StockQuote.kt$StockQuote.Companion$@JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List&lt;Message&gt;</ID>
<ID>LongMethod:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List&lt;Message&gt;</ID> <ID>LongMethod:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List&lt;Message&gt;</ID>
@ -46,15 +46,6 @@
<ID>MagicNumber:WorldTime.kt$WorldTime.Companion$3600</ID> <ID>MagicNumber:WorldTime.kt$WorldTime.Companion$3600</ID>
<ID>MagicNumber:WorldTime.kt$WorldTime.Companion$60</ID> <ID>MagicNumber:WorldTime.kt$WorldTime.Companion$60</ID>
<ID>MagicNumber:WorldTime.kt$WorldTime.Companion$86.4</ID> <ID>MagicNumber:WorldTime.kt$WorldTime.Companion$86.4</ID>
<ID>MaxLineLength:DiceTest.kt$DiceTest$.</ID>
<ID>MaxLineLength:Lookup.kt$Lookup$("(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)")</ID>
<ID>MaxLineLength:Mastodon.kt$Mastodon.Companion$mapOf("status" to "${handle?.prefixIfMissing('@')} $message", "visibility" to "direct")</ID>
<ID>MaxLineLength:Mobibot.kt$Mobibot$helpCmdSyntax("%c ${Constants.HELP_CMD} &lt;command&gt;", event.bot().nick, event is PrivateMessageEvent)</ID>
<ID>MaxLineLength:PinboardTest.kt$PinboardTest$URL("https://api.pinboard.in/v1/posts/get?auth_token=${apiToken}&amp;tag=test&amp;" + url.encodeUrl()).reader().body</ID>
<ID>MaxLineLength:StockQuote.kt$StockQuote.Companion$+</ID>
<ID>MaxLineLength:Utils.kt$Utils$list.subList(i, list.size.coerceAtMost(i + maxPerLine)).joinToString(separator, truncated = "")</ID>
<ID>MaxLineLength:View.kt$View$helpCmdSyntax("%c $name ${index + 1} $query", event.bot().nick, event is PrivateMessageEvent)</ID>
<ID>MaxLineLength:Weather2.kt$Weather2.Companion$country.name.replace('_', ' ').capitalizeWords()</ID>
<ID>NestedBlockDepth:Addons.kt$Addons$fun add(command: AbstractCommand): Boolean</ID> <ID>NestedBlockDepth:Addons.kt$Addons$fun add(command: AbstractCommand): Boolean</ID>
<ID>NestedBlockDepth:Addons.kt$Addons$fun add(module: AbstractModule): Boolean</ID> <ID>NestedBlockDepth:Addons.kt$Addons$fun add(module: AbstractModule): Boolean</ID>
<ID>NestedBlockDepth:ChatGpt.kt$ChatGpt.Companion$@JvmStatic @Throws(ModuleException::class) fun chat(query: String, apiKey: String?, maxTokens: Int): String</ID> <ID>NestedBlockDepth:ChatGpt.kt$ChatGpt.Companion$@JvmStatic @Throws(ModuleException::class) fun chat(query: String, apiKey: String?, maxTokens: Int): String</ID>
@ -62,8 +53,8 @@
<ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter.Companion$@JvmStatic @Throws(ModuleException::class) fun loadSymbols(apiKey: String?)</ID> <ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter.Companion$@JvmStatic @Throws(ModuleException::class) fun loadSymbols(apiKey: String?)</ID>
<ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter.Companion$@JvmStatic fun convertCurrency(apiKey: String?, query: String): Message</ID> <ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter.Companion$@JvmStatic fun convertCurrency(apiKey: String?, query: String): Message</ID>
<ID>NestedBlockDepth:EntryLink.kt$EntryLink$private fun setTags(tags: List&lt;String?&gt;)</ID> <ID>NestedBlockDepth:EntryLink.kt$EntryLink$private fun setTags(tags: List&lt;String?&gt;)</ID>
<ID>NestedBlockDepth:FeedsManager.kt$FeedsManager.Companion$@JvmStatic @Throws(IOException::class, FeedException::class) fun loadFeed(entries: Entries, currentFile: String = currentXml): String</ID> <ID>NestedBlockDepth:FeedsManager.kt$FeedsManager.Companion$@JvmStatic @Throws(IOException::class, FeedException::class) fun loadFeed(entries: Entries, currentFile: String = CURRENT_XML): String</ID>
<ID>NestedBlockDepth:FeedsManager.kt$FeedsManager.Companion$@JvmStatic fun saveFeed(entries: Entries, currentFile: String = currentXml)</ID> <ID>NestedBlockDepth:FeedsManager.kt$FeedsManager.Companion$@JvmStatic fun saveFeed(entries: Entries, currentFile: String = CURRENT_XML)</ID>
<ID>NestedBlockDepth:GoogleSearch.kt$GoogleSearch$override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent)</ID> <ID>NestedBlockDepth:GoogleSearch.kt$GoogleSearch$override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent)</ID>
<ID>NestedBlockDepth:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle( query: String, apiKey: String?, cseKey: String?, quotaUser: String = ReleaseInfo.PROJECT ): List&lt;Message&gt;</ID> <ID>NestedBlockDepth:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle( query: String, apiKey: String?, cseKey: String?, quotaUser: String = ReleaseInfo.PROJECT ): List&lt;Message&gt;</ID>
<ID>NestedBlockDepth:LinksManager.kt$LinksManager$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID> <ID>NestedBlockDepth:LinksManager.kt$LinksManager$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID>

View file

@ -42,7 +42,6 @@ import org.slf4j.Logger
import java.io.* import java.io.*
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.URL import java.net.URL
import java.net.URLEncoder
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import java.time.LocalDateTime import java.time.LocalDateTime
@ -125,16 +124,24 @@ object Utils {
*/ */
@JvmStatic @JvmStatic
fun String?.colorize(color: String): String { fun String?.colorize(color: String): String {
return if (isNullOrEmpty()) { return when {
isNullOrEmpty() -> {
"" ""
} else if (color == DEFAULT_COLOR) { }
color == DEFAULT_COLOR -> {
this this
} else if (Colors.BOLD == color || Colors.REVERSE == color) { }
Colors.BOLD == color || Colors.REVERSE == color -> {
color + this + color color + this + color
} else { }
else -> {
color + this + Colors.NORMAL color + this + Colors.NORMAL
} }
} }
}
/** /**
* Makes the given string cyan. * Makes the given string cyan.

View file

@ -129,7 +129,7 @@ class Ignore : AbstractCommand() {
} }
} }
if (ignored.size > 0) { if (ignored.isNotEmpty()) {
event.sendMessage("The following nicks are ignored:") event.sendMessage("The following nicks are ignored:")
event.sendList(ignored.sorted(), 8, isIndent = true) event.sendList(ignored.sorted(), 8, isIndent = true)
} else { } else {

View file

@ -39,6 +39,7 @@ class NickComparator : Comparator<String>, Serializable {
} }
companion object { companion object {
@Suppress("ConstPropertyName")
private const val serialVersionUID = 1L private const val serialVersionUID = 1L
} }
} }

View file

@ -35,6 +35,7 @@ import java.io.Serializable
data class SeenNick(val nick: String, val lastSeen: Long) : Serializable { data class SeenNick(val nick: String, val lastSeen: Long) : Serializable {
companion object { companion object {
@Suppress("ConstPropertyName")
private const val serialVersionUID = 1L private const val serialVersionUID = 1L
} }
} }

View file

@ -85,19 +85,27 @@ class Tell(private val serialObject: String) : AbstractCommand() {
override fun commandResponse(channel: String, args: String, event: GenericMessageEvent) { override fun commandResponse(channel: String, args: String, event: GenericMessageEvent) {
if (isEnabled()) { if (isEnabled()) {
if (args.isBlank()) { when {
args.isBlank() -> {
helpResponse(channel, args, event) helpResponse(channel, args, event)
} else if (args.startsWith(View.VIEW_CMD)) { }
args.startsWith(View.VIEW_CMD) -> {
if (event.isChannelOp(channel) && "${View.VIEW_CMD} $TELL_ALL_KEYWORD" == args) { if (event.isChannelOp(channel) && "${View.VIEW_CMD} $TELL_ALL_KEYWORD" == args) {
viewAll(event) viewAll(event)
} else { } else {
viewMessages(event) viewMessages(event)
} }
} else if (args.startsWith("$TELL_DEL_KEYWORD ")) { }
args.startsWith("$TELL_DEL_KEYWORD ") -> {
deleteMessage(channel, args, event) deleteMessage(channel, args, event)
} else { }
else -> {
newMessage(channel, args, event) newMessage(channel, args, event)
} }
}
if (clean()) { if (clean()) {
save() save()
} }

View file

@ -98,6 +98,7 @@ class TellMessage(
} }
companion object { companion object {
@Suppress("ConstPropertyName")
private const val serialVersionUID = 2L private const val serialVersionUID = 2L
} }
} }

View file

@ -46,6 +46,7 @@ data class EntryComment(var comment: String, var nick: String) : Serializable {
companion object { companion object {
// Serial version UID // Serial version UID
@Suppress("ConstPropertyName")
private const val serialVersionUID: Long = 1L private const val serialVersionUID: Long = 1L
} }
} }

View file

@ -207,6 +207,7 @@ class EntryLink(
companion object { companion object {
// Serial version UID // Serial version UID
@Suppress("ConstPropertyName")
private const val serialVersionUID: Long = 1L private const val serialVersionUID: Long = 1L
} }
} }

View file

@ -55,17 +55,17 @@ class FeedsManager private constructor() {
private val logger: Logger = LoggerFactory.getLogger(FeedsManager::class.java) private val logger: Logger = LoggerFactory.getLogger(FeedsManager::class.java)
// The file containing the current entries. // The file containing the current entries.
private const val currentXml = "current.xml" private const val CURRENT_XML = "current.xml"
// The .xml extension. // The .xml extension.
private const val dotXml = ".xml" private const val DOT_XML = ".xml"
/** /**
* Loads the current feed. * Loads the current feed.
*/ */
@JvmStatic @JvmStatic
@Throws(IOException::class, FeedException::class) @Throws(IOException::class, FeedException::class)
fun loadFeed(entries: Entries, currentFile: String = currentXml): String { fun loadFeed(entries: Entries, currentFile: String = CURRENT_XML): String {
entries.links.clear() entries.links.clear()
val xml = Paths.get("${entries.logsDir}${currentFile}") val xml = Paths.get("${entries.logsDir}${currentFile}")
var pubDate = today() var pubDate = today()
@ -110,7 +110,7 @@ class FeedsManager private constructor() {
* Saves the feeds. * Saves the feeds.
*/ */
@JvmStatic @JvmStatic
fun saveFeed(entries: Entries, currentFile: String = currentXml) { fun saveFeed(entries: Entries, currentFile: String = CURRENT_XML) {
if (logger.isDebugEnabled) logger.debug("Saving the feeds...") if (logger.isDebugEnabled) logger.debug("Saving the feeds...")
if (entries.logsDir.isNotBlank()) { if (entries.logsDir.isNotBlank()) {
try { try {
@ -141,7 +141,7 @@ class FeedsManager private constructor() {
.append("\"><b>") .append("\"><b>")
.append(channel) .append(channel)
.append("</b></a>") .append("</b></a>")
if (comments.size > 0) { if (comments.isNotEmpty()) {
buff.append(" <br/><br/>") buff.append(" <br/><br/>")
for (j in comments.indices) { for (j in comments.indices) {
if (j > 0) { if (j > 0) {
@ -167,7 +167,7 @@ class FeedsManager private constructor() {
OutputStreamWriter( OutputStreamWriter(
Files.newOutputStream( Files.newOutputStream(
Paths.get( Paths.get(
entries.logsDir + today() + dotXml entries.logsDir + today() + DOT_XML
) )
), StandardCharsets.UTF_8 ), StandardCharsets.UTF_8
).use { fw -> output.output(rss, fw) } ).use { fw -> output.output(rss, fw) }

View file

@ -74,21 +74,29 @@ class CurrencyConverter : AbstractModule() {
override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) { override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) {
reload(properties[API_KEY_PROP]) reload(properties[API_KEY_PROP])
if (SYMBOLS.isEmpty()) { when {
SYMBOLS.isEmpty() -> {
event.respond(EMPTY_SYMBOLS_TABLE) event.respond(EMPTY_SYMBOLS_TABLE)
} else if (args.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ (to|in) [a-zA-Z]{3}+".toRegex())) { }
args.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ (to|in) [a-zA-Z]{3}+".toRegex()) -> {
val msg = convertCurrency(properties[API_KEY_PROP], args) val msg = convertCurrency(properties[API_KEY_PROP], args)
event.respond(msg.msg) event.respond(msg.msg)
if (msg.isError) { if (msg.isError) {
helpResponse(event) helpResponse(event)
} }
} else if (args.contains(CODES_KEYWORD)) { }
args.contains(CODES_KEYWORD) -> {
event.sendMessage("The supported currency codes are:") event.sendMessage("The supported currency codes are:")
event.sendList(SYMBOLS.keys.toList(), 11, isIndent = true) event.sendList(SYMBOLS.keys.toList(), 11, isIndent = true)
} else { }
else -> {
helpResponse(event) helpResponse(event)
} }
} }
}
override fun helpResponse(event: GenericMessageEvent): Boolean { override fun helpResponse(event: GenericMessageEvent): Boolean {
reload(properties[API_KEY_PROP]) reload(properties[API_KEY_PROP])

View file

@ -39,6 +39,7 @@ class ModuleException @JvmOverloads constructor(
cause: Throwable? = null cause: Throwable? = null
) : Exception(message, cause) { ) : Exception(message, cause) {
companion object { companion object {
@Suppress("ConstPropertyName")
private const val serialVersionUID = 1L private const val serialVersionUID = 1L
} }
} }

View file

@ -49,7 +49,7 @@ import org.testng.annotations.Test
/** /**
* The `CurrencyConvertTest` class. * The `CurrencyConvertTest` class.
*/ */
class CurrencyConverterTest: LocalProperties() { class CurrencyConverterTest : LocalProperties() {
@BeforeClass @BeforeClass
@Throws(ModuleException::class) @Throws(ModuleException::class)
@ -62,22 +62,22 @@ class CurrencyConverterTest: LocalProperties() {
fun testConvertCurrency() { fun testConvertCurrency() {
val apiKey = getProperty(CurrencyConverter.API_KEY_PROP) val apiKey = getProperty(CurrencyConverter.API_KEY_PROP)
assertThat( assertThat(
convertCurrency(apiKey,"100 USD to EUR").msg, convertCurrency(apiKey, "100 USD to EUR").msg,
"convertCurrency(100 USD to EUR)" "convertCurrency(100 USD to EUR)"
).matches("100 United States Dollar = \\d{2,3}\\.\\d{2,3} Euro".toRegex()) ).matches("100 United States Dollar = \\d{2,3}\\.\\d{2,3} Euro".toRegex())
assertThat( assertThat(
convertCurrency(apiKey,"1 USD to GBP").msg, convertCurrency(apiKey, "1 USD to GBP").msg,
"convertCurrency(1 USD to BGP)" "convertCurrency(1 USD to BGP)"
).matches("1 United States Dollar = 0\\.\\d{2,3} Pound Sterling".toRegex()) ).matches("1 United States Dollar = 0\\.\\d{2,3} Pound Sterling".toRegex())
assertThat( assertThat(
convertCurrency(apiKey,"100,000.00 CAD to USD").msg, convertCurrency(apiKey, "100,000.00 CAD to USD").msg,
"convertCurrency(100,000.00 GBP to USD)" "convertCurrency(100,000.00 GBP to USD)"
).matches("100,000.00 Canadian Dollar = \\d+\\.\\d{2,3} United States Dollar".toRegex()) ).matches("100,000.00 Canadian Dollar = \\d+\\.\\d{2,3} United States Dollar".toRegex())
assertThat(convertCurrency(apiKey,"100 USD to USD"), "convertCurrency(100 USD to USD)").all { assertThat(convertCurrency(apiKey, "100 USD to USD"), "convertCurrency(100 USD to USD)").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(apiKey,"100 USD"), "convertCurrency(100 USD)").all { assertThat(convertCurrency(apiKey, "100 USD"), "convertCurrency(100 USD)").all {
prop(Message::msg).contains("Invalid query.") prop(Message::msg).contains("Invalid query.")
isInstanceOf(ErrorMessage::class.java) isInstanceOf(ErrorMessage::class.java)
} }

View file

@ -44,33 +44,33 @@ import java.lang.reflect.Method
*/ */
class ModuleExceptionTest { class ModuleExceptionTest {
companion object { companion object {
const val debugMessage = "debugMessage" const val DEBUG_MESSAGE = "debugMessage"
const val message = "message" const val MESSAGE = "message"
} }
@DataProvider(name = "dp") @DataProvider(name = "dp")
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(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com"))),
arrayOf(ModuleException(debugMessage, message, IOException("URL http://foobar.com?"))), arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com?"))),
arrayOf(ModuleException(debugMessage, message)) arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE))
) )
} }
@Test(dataProvider = "dp") @Test(dataProvider = "dp")
fun testGetDebugMessage(e: ModuleException) { fun testGetDebugMessage(e: ModuleException) {
assertThat(e::debugMessage).isEqualTo(debugMessage) assertThat(e::debugMessage).isEqualTo(DEBUG_MESSAGE)
} }
@Test(dataProvider = "dp") @Test(dataProvider = "dp")
fun testGetMessage(e: ModuleException) { fun testGetMessage(e: ModuleException) {
assertThat(e).hasMessage(message) assertThat(e).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(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foo.com?apiKey=$apiKey&userID=me"))
assertThat( assertThat(
e.sanitize(apiKey, "", "me").message, "ModuleException(debugMessage, message, IOException(url))" e.sanitize(apiKey, "", "me").message, "ModuleException(debugMessage, message, IOException(url))"
).isNotNull().all { ).isNotNull().all {
@ -78,21 +78,21 @@ class ModuleExceptionTest {
doesNotContain(apiKey, "me") doesNotContain(apiKey, "me")
} }
e = ModuleException(debugMessage, message, null) e = ModuleException(DEBUG_MESSAGE, MESSAGE, null)
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, null)").hasMessage(message) assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, null)").hasMessage(MESSAGE)
e = ModuleException(debugMessage, message, IOException()) e = ModuleException(DEBUG_MESSAGE, MESSAGE, IOException())
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, IOException())").hasMessage(message) assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, IOException())").hasMessage(MESSAGE)
e = ModuleException(debugMessage, apiKey) e = ModuleException(DEBUG_MESSAGE, apiKey)
assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, apiKey)").isNotNull() assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, apiKey)").isNotNull()
.doesNotContain(apiKey) .doesNotContain(apiKey)
val msg: String? = null val msg: String? = null
e = ModuleException(debugMessage, msg, IOException(msg)) e = ModuleException(DEBUG_MESSAGE, msg, IOException(msg))
assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, msg, IOException(msg))").isNull() assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, msg, IOException(msg))").isNull()
e = ModuleException(debugMessage, msg, IOException("foo is $apiKey")) e = ModuleException(DEBUG_MESSAGE, msg, IOException("foo is $apiKey"))
assertThat( assertThat(
e.sanitize(" ", apiKey, "foo").message, e.sanitize(" ", apiKey, "foo").message,
"ModuleException(debugMessage, msg, IOException(foo is $apiKey))" "ModuleException(debugMessage, msg, IOException(foo is $apiKey))"

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle #Generated by the Semver Plugin for Gradle
#Thu Oct 26 20:43:39 PDT 2023 #Wed Nov 01 22:09:32 PDT 2023
version.buildmeta=20231026204339 version.buildmeta=20231101220932
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+20231026204339 version.semver=0.8.0-rc+20231101220932