Cleaned up code

This commit is contained in:
Erik C. Thauvin 2023-11-01 22:02:54 -07:00
parent d700aa06df
commit 4c90870f4a
61 changed files with 496 additions and 481 deletions

View file

@ -128,12 +128,15 @@ object Utils {
isNullOrEmpty() -> { isNullOrEmpty() -> {
"" ""
} }
color == DEFAULT_COLOR -> { color == DEFAULT_COLOR -> {
this this
} }
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
} }

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

@ -89,6 +89,7 @@ class Tell(private val serialObject: String) : AbstractCommand() {
args.isBlank() -> { args.isBlank() -> {
helpResponse(channel, args, event) helpResponse(channel, args, event)
} }
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)
@ -96,9 +97,11 @@ class Tell(private val serialObject: String) : AbstractCommand() {
viewMessages(event) viewMessages(event)
} }
} }
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)
} }

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 {
@ -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

@ -78,6 +78,7 @@ class CurrencyConverter : AbstractModule() {
SYMBOLS.isEmpty() -> { SYMBOLS.isEmpty() -> {
event.respond(EMPTY_SYMBOLS_TABLE) event.respond(EMPTY_SYMBOLS_TABLE)
} }
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)
@ -85,10 +86,12 @@ class CurrencyConverter : AbstractModule() {
helpResponse(event) helpResponse(event)
} }
} }
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)
} }

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))"