Rewrites MaintenancePluginTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-18 22:56:29 -07:00
parent a9259ed7a6
commit e7f1cb0be6

View file

@ -1,6 +1,7 @@
package info.nightscout.plugins.general.maintenance package info.nightscout.plugins.general.maintenance
import android.content.Context import android.content.Context
import com.google.common.truth.Truth.assertThat
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.configuration.maintenance.MaintenancePlugin import info.nightscout.configuration.maintenance.MaintenancePlugin
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
@ -10,7 +11,6 @@ import info.nightscout.interfaces.nsclient.NSSettingsStatus
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 info.nightscout.sharedtests.TestBase import info.nightscout.sharedtests.TestBase
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
@ -40,11 +40,12 @@ class MaintenancePluginTest : TestBase() {
@Test fun logFilesTest() { @Test fun logFilesTest() {
var logs = sut.getLogFiles(2) var logs = sut.getLogFiles(2)
Assertions.assertEquals(2, logs.size) assertThat(logs.map { it.name }).containsExactly(
Assertions.assertEquals("AndroidAPS.log", logs[0].name) "AndroidAPS.log",
Assertions.assertEquals("AndroidAPS.2018-01-03_01-01-00.1.zip", logs[1].name) "AndroidAPS.2018-01-03_01-01-00.1.zip",
).inOrder()
logs = sut.getLogFiles(10) logs = sut.getLogFiles(10)
Assertions.assertEquals(4, logs.size) assertThat(logs).hasSize(4)
} }
@Test @Test
@ -53,7 +54,7 @@ class MaintenancePluginTest : TestBase() {
val name = "AndroidAPS.log.zip" val name = "AndroidAPS.log.zip"
var zipFile = File("build/$name") var zipFile = File("build/$name")
zipFile = sut.zipLogs(zipFile, logs) zipFile = sut.zipLogs(zipFile, logs)
Assertions.assertTrue(zipFile.exists()) assertThat(zipFile.exists()).isTrue()
Assertions.assertTrue(zipFile.isFile) assertThat(zipFile.isFile).isTrue()
} }
} }