Rewrites ActionCarePortalEventTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-04 21:54:33 -07:00
parent 3a88e89a80
commit f51206e417

View file

@ -8,11 +8,12 @@ import app.aaps.plugins.automation.elements.InputCarePortalMenu
import app.aaps.plugins.automation.elements.InputDuration import app.aaps.plugins.automation.elements.InputDuration
import app.aaps.plugins.automation.elements.InputString import app.aaps.plugins.automation.elements.InputString
import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.core.Single
import org.junit.jupiter.api.Assertions import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import org.skyscreamer.jsonassert.JSONAssert
class ActionCarePortalEventTest : ActionsTestBase() { class ActionCarePortalEventTest : ActionsTestBase() {
@ -35,41 +36,42 @@ class ActionCarePortalEventTest : ActionsTestBase() {
} }
@Test fun friendlyNameTest() { @Test fun friendlyNameTest() {
Assertions.assertEquals(app.aaps.core.ui.R.string.careportal, sut.friendlyName()) assertThat(sut.friendlyName()).isEqualTo(app.aaps.core.ui.R.string.careportal)
} }
@Test fun shortDescriptionTest() { @Test fun shortDescriptionTest() {
Assertions.assertEquals("Note : Asd", sut.shortDescription()) assertThat(sut.shortDescription()).isEqualTo("Note : Asd")
} }
@Test fun iconTest() { @Test fun iconTest() {
Assertions.assertEquals(app.aaps.core.main.R.drawable.ic_cp_note, sut.icon()) assertThat(sut.icon()).isEqualTo(app.aaps.core.main.R.drawable.ic_cp_note)
} }
@Test fun doActionTest() { @Test fun doActionTest() {
sut.doAction(object : Callback() { sut.doAction(object : Callback() {
override fun run() { override fun run() {
Assertions.assertTrue(result.success) assertThat(result.success).isTrue()
} }
}) })
} }
@Test fun hasDialogTest() { @Test fun hasDialogTest() {
Assertions.assertTrue(sut.hasDialog()) assertThat(sut.hasDialog()).isTrue()
} }
@Test fun toJSONTest() { @Test fun toJSONTest() {
Assertions.assertEquals( JSONAssert.assertEquals(
"{\"data\":{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5},\"type\":\"ActionCarePortalEvent\"}", """{"data":{"note":"Asd","cpEvent":"NOTE","durationInMinutes":5},"type":"ActionCarePortalEvent"}""",
sut.toJSON() sut.toJSON(),
true,
) )
} }
@Test fun fromJSONTest() { @Test fun fromJSONTest() {
sut.note = InputString("Asd") sut.note = InputString("Asd")
sut.fromJSON("{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5}") sut.fromJSON("""{"note":"Asd","cpEvent":"NOTE","durationInMinutes":5}""")
Assertions.assertEquals("Asd", sut.note.value) assertThat(sut.note.value).isEqualTo("Asd")
Assertions.assertEquals(5, sut.duration.value) assertThat(sut.duration.value).isEqualTo(5)
Assertions.assertEquals(InputCarePortalMenu.EventType.NOTE, sut.cpEvent.value) assertThat(sut.cpEvent.value).isEqualTo(InputCarePortalMenu.EventType.NOTE)
} }
} }