Cleaned up messages classes.
This commit is contained in:
parent
8efb09cea8
commit
f1b50d741c
6 changed files with 51 additions and 66 deletions
|
@ -34,10 +34,5 @@ package net.thauvin.erik.mobibot.msg
|
|||
/**
|
||||
* The `ErrorMessage` class.
|
||||
*/
|
||||
class ErrorMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
||||
init {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
isError = true
|
||||
}
|
||||
}
|
||||
class ErrorMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) :
|
||||
Message(msg, color, isError = true)
|
||||
|
|
|
@ -36,53 +36,31 @@ import net.thauvin.erik.semver.Constants
|
|||
/**
|
||||
* The `Message` class.
|
||||
*/
|
||||
open class Message {
|
||||
open class Message @JvmOverloads constructor(
|
||||
var msg: String,
|
||||
var color: String = DEFAULT_COLOR,
|
||||
var isNotice: Boolean = false,
|
||||
isError: Boolean = false,
|
||||
var isPrivate: Boolean = false
|
||||
) {
|
||||
companion object {
|
||||
var DEFAULT_COLOR = Constants.EMPTY
|
||||
|
||||
}
|
||||
|
||||
/** Message color. */
|
||||
var color = DEFAULT_COLOR
|
||||
init {
|
||||
if (isError) {
|
||||
isNotice = true
|
||||
}
|
||||
}
|
||||
|
||||
/** Error flag. */
|
||||
var isError = false
|
||||
var isError = isError
|
||||
set(value) {
|
||||
if (value) isNotice = value
|
||||
field = value
|
||||
}
|
||||
|
||||
/** Notice flag. */
|
||||
var isNotice = false
|
||||
|
||||
/** Private flag. */
|
||||
var isPrivate = false
|
||||
|
||||
/** Message text. */
|
||||
var msg = ""
|
||||
|
||||
/** Creates a new message. */
|
||||
constructor() {
|
||||
// This constructor is intentionally empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new message.
|
||||
*/
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
msg: String,
|
||||
color: String = DEFAULT_COLOR,
|
||||
isNotice: Boolean = false,
|
||||
isError: Boolean = false,
|
||||
isPrivate: Boolean = false
|
||||
) {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
this.isNotice = isNotice
|
||||
this.isError = isError
|
||||
this.isPrivate = isPrivate
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "Message(color='$color', isError=$isError, isNotice=$isNotice, isPrivate=$isPrivate, msg='$msg')"
|
||||
}
|
||||
|
|
|
@ -34,10 +34,6 @@ package net.thauvin.erik.mobibot.msg
|
|||
/**
|
||||
* The `NoticeMessage` class.
|
||||
*/
|
||||
class NoticeMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
||||
init {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
isNotice = true
|
||||
}
|
||||
}
|
||||
class NoticeMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) :
|
||||
Message(msg, color, isNotice = true)
|
||||
|
||||
|
|
|
@ -34,11 +34,5 @@ package net.thauvin.erik.mobibot.msg
|
|||
/**
|
||||
* The `PrivateMessage` class.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
class PrivateMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
||||
init {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
isPrivate = true
|
||||
}
|
||||
}
|
||||
class PrivateMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) :
|
||||
Message(msg, color, isPrivate = true)
|
||||
|
|
|
@ -34,9 +34,4 @@ package net.thauvin.erik.mobibot.msg
|
|||
/**
|
||||
* The `PublicMessage` class.
|
||||
*/
|
||||
class PublicMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
||||
init {
|
||||
this.msg = msg
|
||||
this.color = color
|
||||
}
|
||||
}
|
||||
class PublicMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message(msg, color)
|
||||
|
|
|
@ -32,14 +32,17 @@
|
|||
|
||||
package net.thauvin.erik.mobibot.msg
|
||||
|
||||
import assertk.all
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isFalse
|
||||
import assertk.assertions.isTrue
|
||||
import assertk.assertions.prop
|
||||
import org.testng.annotations.Test
|
||||
|
||||
class TestMessage {
|
||||
@Test
|
||||
fun testConstructor() {
|
||||
var msg = Message()
|
||||
var msg = Message("foo")
|
||||
|
||||
msg.isError = true
|
||||
assertThat(msg.isNotice, "message is notice").isTrue()
|
||||
|
@ -51,6 +54,30 @@ class TestMessage {
|
|||
@Test
|
||||
fun testErrorMessage() {
|
||||
val msg = ErrorMessage("foo")
|
||||
assertThat(msg.isNotice, "error message is notice").isTrue()
|
||||
assertThat(msg).all {
|
||||
prop(Message::isError).isTrue()
|
||||
prop(Message::isNotice).isTrue()
|
||||
prop(Message::isPrivate).isFalse()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoticeMessage() {
|
||||
val msg = NoticeMessage("food")
|
||||
assertThat(msg).all {
|
||||
prop(Message::isError).isFalse()
|
||||
prop(Message::isNotice).isTrue()
|
||||
prop(Message::isPrivate).isFalse()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPublicMessage() {
|
||||
val msg = PublicMessage("foo")
|
||||
assertThat(msg).all {
|
||||
prop(Message::isError).isFalse()
|
||||
prop(Message::isNotice).isFalse()
|
||||
prop(Message::isPrivate).isFalse()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue