Cleaned up and added test to messages.

This commit is contained in:
Erik C. Thauvin 2021-07-30 12:23:52 -07:00
parent 00caee4bc1
commit d05499a76f
3 changed files with 66 additions and 3 deletions

View file

@ -39,6 +39,5 @@ class ErrorMessage @JvmOverloads constructor(msg: String, color: String = DEFAUL
this.msg = msg
this.color = color
isError = true
isNotice = true
}
}

View file

@ -32,7 +32,6 @@
package net.thauvin.erik.mobibot.msg
import net.thauvin.erik.semver.Constants
import org.jibble.pircbot.Colors
/**
* The `Message` class.
@ -47,6 +46,10 @@ open class Message {
/** Error flag. */
var isError = false
set(value) {
if (value) isNotice = value
field = value
}
/** Notice flag. */
var isNotice = false
@ -66,7 +69,13 @@ open class Message {
* Creates a new message.
*/
@JvmOverloads
constructor(msg: String, color: String = DEFAULT_COLOR, isNotice: Boolean, isError: Boolean, isPrivate: Boolean) {
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

View file

@ -0,0 +1,55 @@
/*
* TestMessage.kt
*
* Copyright (c) 2004-2021, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of this project nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.thauvin.erik.mobibot.msg
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
class TestMessage {
@Test
fun testConstructor() {
var msg = Message()
msg.isError = true
assertThat(msg.isNotice).describedAs("message is notice").isTrue
msg = Message("foo", isError = true)
assertThat(msg.isNotice).describedAs("message is notice too").isTrue
}
@Test
fun testErrorMessage() {
val msg = ErrorMessage("foo")
assertThat(msg.isNotice).describedAs("error message is notice").isTrue
}
}