diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/msg/ErrorMessage.kt b/src/main/kotlin/net/thauvin/erik/mobibot/msg/ErrorMessage.kt index 96ef549..741d557 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/msg/ErrorMessage.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/msg/ErrorMessage.kt @@ -39,6 +39,5 @@ class ErrorMessage @JvmOverloads constructor(msg: String, color: String = DEFAUL this.msg = msg this.color = color isError = true - isNotice = true } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/msg/Message.kt b/src/main/kotlin/net/thauvin/erik/mobibot/msg/Message.kt index c1ced5f..b410663 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/msg/Message.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/msg/Message.kt @@ -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 diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/msg/TestMessage.kt b/src/test/kotlin/net/thauvin/erik/mobibot/msg/TestMessage.kt new file mode 100644 index 0000000..6ab62c9 --- /dev/null +++ b/src/test/kotlin/net/thauvin/erik/mobibot/msg/TestMessage.kt @@ -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 + } +}