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.
|
* The `ErrorMessage` class.
|
||||||
*/
|
*/
|
||||||
class ErrorMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
class ErrorMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) :
|
||||||
init {
|
Message(msg, color, isError = true)
|
||||||
this.msg = msg
|
|
||||||
this.color = color
|
|
||||||
isError = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -36,53 +36,31 @@ import net.thauvin.erik.semver.Constants
|
||||||
/**
|
/**
|
||||||
* The `Message` class.
|
* 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 {
|
companion object {
|
||||||
var DEFAULT_COLOR = Constants.EMPTY
|
var DEFAULT_COLOR = Constants.EMPTY
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Message color. */
|
init {
|
||||||
var color = DEFAULT_COLOR
|
if (isError) {
|
||||||
|
isNotice = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Error flag. */
|
/** Error flag. */
|
||||||
var isError = false
|
var isError = isError
|
||||||
set(value) {
|
set(value) {
|
||||||
if (value) isNotice = value
|
if (value) isNotice = value
|
||||||
field = 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 {
|
override fun toString(): String {
|
||||||
return "Message(color='$color', isError=$isError, isNotice=$isNotice, isPrivate=$isPrivate, msg='$msg')"
|
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.
|
* The `NoticeMessage` class.
|
||||||
*/
|
*/
|
||||||
class NoticeMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
class NoticeMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) :
|
||||||
init {
|
Message(msg, color, isNotice = true)
|
||||||
this.msg = msg
|
|
||||||
this.color = color
|
|
||||||
isNotice = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,11 +34,5 @@ package net.thauvin.erik.mobibot.msg
|
||||||
/**
|
/**
|
||||||
* The `PrivateMessage` class.
|
* The `PrivateMessage` class.
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
class PrivateMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) :
|
||||||
class PrivateMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
Message(msg, color, isPrivate = true)
|
||||||
init {
|
|
||||||
this.msg = msg
|
|
||||||
this.color = color
|
|
||||||
isPrivate = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,9 +34,4 @@ package net.thauvin.erik.mobibot.msg
|
||||||
/**
|
/**
|
||||||
* The `PublicMessage` class.
|
* The `PublicMessage` class.
|
||||||
*/
|
*/
|
||||||
class PublicMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message() {
|
class PublicMessage @JvmOverloads constructor(msg: String, color: String = DEFAULT_COLOR) : Message(msg, color)
|
||||||
init {
|
|
||||||
this.msg = msg
|
|
||||||
this.color = color
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,14 +32,17 @@
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot.msg
|
package net.thauvin.erik.mobibot.msg
|
||||||
|
|
||||||
|
import assertk.all
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
|
import assertk.assertions.isFalse
|
||||||
import assertk.assertions.isTrue
|
import assertk.assertions.isTrue
|
||||||
|
import assertk.assertions.prop
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
class TestMessage {
|
class TestMessage {
|
||||||
@Test
|
@Test
|
||||||
fun testConstructor() {
|
fun testConstructor() {
|
||||||
var msg = Message()
|
var msg = Message("foo")
|
||||||
|
|
||||||
msg.isError = true
|
msg.isError = true
|
||||||
assertThat(msg.isNotice, "message is notice").isTrue()
|
assertThat(msg.isNotice, "message is notice").isTrue()
|
||||||
|
@ -51,6 +54,30 @@ class TestMessage {
|
||||||
@Test
|
@Test
|
||||||
fun testErrorMessage() {
|
fun testErrorMessage() {
|
||||||
val msg = ErrorMessage("foo")
|
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