Rewrites DstHelperPluginTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-23 17:49:53 -07:00
parent 343e2fe6fb
commit 392cd48ff5

View file

@ -1,13 +1,13 @@
package info.nightscout.plugins.constraints.dstHelper package info.nightscout.plugins.constraints.dstHelper
import app.aaps.shared.tests.TestBase import app.aaps.shared.tests.TestBase
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
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
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
@ -41,31 +41,31 @@ class DstHelperPluginTest : TestBase() {
val df: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ITALIAN) val df: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.ITALIAN)
var dateBeforeDST = df.parse("2018-03-25 01:55") var dateBeforeDST = df.parse("2018-03-25 01:55")
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(false, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isFalse()
Assertions.assertEquals(true, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isTrue()
TimeZone.setDefault(tz) TimeZone.setDefault(tz)
cal = Calendar.getInstance(tz, Locale.ITALIAN) cal = Calendar.getInstance(tz, Locale.ITALIAN)
dateBeforeDST = df.parse("2018-03-25 03:05") dateBeforeDST = df.parse("2018-03-25 03:05")
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(true, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isTrue()
Assertions.assertEquals(false, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isFalse()
TimeZone.setDefault(tz) TimeZone.setDefault(tz)
cal = Calendar.getInstance(tz, Locale.ITALIAN) cal = Calendar.getInstance(tz, Locale.ITALIAN)
dateBeforeDST = df.parse("2018-03-25 02:05") //Cannot happen!!! dateBeforeDST = df.parse("2018-03-25 02:05") //Cannot happen!!!
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(true, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isTrue()
Assertions.assertEquals(false, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isFalse()
TimeZone.setDefault(tz) TimeZone.setDefault(tz)
cal = Calendar.getInstance(tz, Locale.ITALIAN) cal = Calendar.getInstance(tz, Locale.ITALIAN)
dateBeforeDST = df.parse("2018-03-25 05:55") //Cannot happen!!! dateBeforeDST = df.parse("2018-03-25 05:55") //Cannot happen!!!
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(true, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isTrue()
Assertions.assertEquals(false, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isFalse()
TimeZone.setDefault(tz) TimeZone.setDefault(tz)
cal = Calendar.getInstance(tz, Locale.ITALIAN) cal = Calendar.getInstance(tz, Locale.ITALIAN)
dateBeforeDST = df.parse("2018-03-25 06:05") //Cannot happen!!! dateBeforeDST = df.parse("2018-03-25 06:05") //Cannot happen!!!
cal.time = dateBeforeDST!! cal.time = dateBeforeDST!!
Assertions.assertEquals(false, plugin.wasDST(cal)) assertThat(plugin.wasDST(cal)).isFalse()
Assertions.assertEquals(false, plugin.willBeDST(cal)) assertThat(plugin.willBeDST(cal)).isFalse()
} }
} }