Rewrites QuickWizardTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-20 23:17:03 -07:00
parent a49a104475
commit 78ed9bc484

View file

@ -1,5 +1,6 @@
package info.nightscout.core.wizard package info.nightscout.core.wizard
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.aps.Loop
@ -7,7 +8,6 @@ import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
import org.json.JSONArray import org.json.JSONArray
import org.junit.jupiter.api.Assertions
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.Mock import org.mockito.Mock
@ -55,46 +55,46 @@ class QuickWizardTest : TestBase() {
@Test @Test
fun setDataTest() { fun setDataTest() {
quickWizard.setData(array) quickWizard.setData(array)
Assertions.assertEquals(2, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(2)
} }
@Test @Test
fun test() { fun test() {
quickWizard.setData(array) quickWizard.setData(array)
Assertions.assertEquals("Lunch", quickWizard[1].buttonText()) assertThat(quickWizard[1].buttonText()).isEqualTo("Lunch")
} }
@Test @Test
fun active() { fun active() {
quickWizard.setData(array) quickWizard.setData(array)
val e: QuickWizardEntry = quickWizard.getActive()!! val e: QuickWizardEntry = quickWizard.getActive()!!
Assertions.assertEquals(36.0, e.carbs().toDouble(), 0.01) assertThat(e.carbs().toDouble()).isWithin(0.01).of(36.0)
quickWizard.remove(0) quickWizard.remove(0)
quickWizard.remove(0) quickWizard.remove(0)
Assertions.assertNull(quickWizard.getActive()) assertThat(quickWizard.getActive()).isNull()
} }
@Test @Test
fun newEmptyItemTest() { fun newEmptyItemTest() {
Assertions.assertNotNull(quickWizard.newEmptyItem()) assertThat(quickWizard.newEmptyItem()).isNotNull()
} }
@Test @Test
fun addOrUpdate() { fun addOrUpdate() {
quickWizard.setData(array) quickWizard.setData(array)
Assertions.assertEquals(2, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(2)
quickWizard.addOrUpdate(quickWizard.newEmptyItem()) quickWizard.addOrUpdate(quickWizard.newEmptyItem())
Assertions.assertEquals(3, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(3)
val q: QuickWizardEntry = quickWizard.newEmptyItem() val q: QuickWizardEntry = quickWizard.newEmptyItem()
q.position = 0 q.position = 0
quickWizard.addOrUpdate(q) quickWizard.addOrUpdate(q)
Assertions.assertEquals(3, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(3)
} }
@Test @Test
fun remove() { fun remove() {
quickWizard.setData(array) quickWizard.setData(array)
quickWizard.remove(0) quickWizard.remove(0)
Assertions.assertEquals(1, quickWizard.size()) assertThat(quickWizard.size()).isEqualTo(1)
} }
} }