Rewrites SmsActionTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-23 18:54:29 -07:00
parent 2cbcf8bd50
commit 2975da80c2

View file

@ -1,6 +1,6 @@
package info.nightscout.plugins.general.smsCommunicator package info.nightscout.plugins.general.smsCommunicator
import org.junit.jupiter.api.Assertions import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class SmsActionTest { class SmsActionTest {
@ -13,49 +13,49 @@ class SmsActionTest {
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "A") assertThat(result).isEqualTo("A")
smsAction = object : SmsAction(false, 1.0) { smsAction = object : SmsAction(false, 1.0) {
override fun run() { override fun run() {
result = "B" result = "B"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "B") assertThat(result).isEqualTo("B")
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001) assertThat(smsAction.aDouble()).isWithin(0.000001).of(1.0)
smsAction = object : SmsAction(false, 1.0, 2) { smsAction = object : SmsAction(false, 1.0, 2) {
override fun run() { override fun run() {
result = "C" result = "C"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "C") assertThat(result).isEqualTo("C")
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001) assertThat(smsAction.aDouble()).isWithin(0.000001).of(1.0)
Assertions.assertEquals(smsAction.secondInteger().toLong(), 2) assertThat(smsAction.secondInteger().toLong()).isEqualTo(2)
smsAction = object : SmsAction(false, "aString", 3) { smsAction = object : SmsAction(false, "aString", 3) {
override fun run() { override fun run() {
result = "D" result = "D"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "D") assertThat(result).isEqualTo("D")
Assertions.assertEquals(smsAction.aString(), "aString") assertThat(smsAction.aString()).isEqualTo("aString")
Assertions.assertEquals(smsAction.secondInteger().toLong(), 3) assertThat(smsAction.secondInteger().toLong()).isEqualTo(3)
smsAction = object : SmsAction(false, 4) { smsAction = object : SmsAction(false, 4) {
override fun run() { override fun run() {
result = "E" result = "E"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "E") assertThat(result).isEqualTo("E")
Assertions.assertEquals(smsAction.anInteger().toLong(), 4) assertThat(smsAction.anInteger().toLong()).isEqualTo(4)
smsAction = object : SmsAction(false, 5, 6) { smsAction = object : SmsAction(false, 5, 6) {
override fun run() { override fun run() {
result = "F" result = "F"
} }
} }
smsAction.run() smsAction.run()
Assertions.assertEquals(result, "F") assertThat(result).isEqualTo("F")
Assertions.assertEquals(smsAction.anInteger().toLong(), 5) assertThat(smsAction.anInteger().toLong()).isEqualTo(5)
Assertions.assertEquals(smsAction.secondInteger().toLong(), 6) assertThat(smsAction.secondInteger().toLong()).isEqualTo(6)
} }
} }