update unit tests

This commit is contained in:
Adam Velebil 2024-03-13 11:14:11 +01:00
parent 9a19a9c608
commit 4490547e2d
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
2 changed files with 11 additions and 12 deletions

View File

@ -17,6 +17,7 @@
package com.yubico.authenticator.oath package com.yubico.authenticator.oath
import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.yubico.authenticator.ViewModelData
import com.yubico.authenticator.device.Version import com.yubico.authenticator.device.Version
import com.yubico.authenticator.oath.OathTestHelper.code import com.yubico.authenticator.oath.OathTestHelper.code
import com.yubico.authenticator.oath.OathTestHelper.emptyCredentials import com.yubico.authenticator.oath.OathTestHelper.emptyCredentials
@ -40,13 +41,12 @@ class ModelTest {
private fun connectDevice(deviceId: String) { private fun connectDevice(deviceId: String) {
viewModel.setSessionState( viewModel.setSessionState(
Session( Session(
deviceId, deviceId,
Version(1, 2, 3), Version(1, 2, 3),
isAccessKeySet = false, isAccessKeySet = false,
isRemembered = false, isRemembered = false,
isLocked = false, isLocked = false
initialized = true )
)
) )
} }
@ -117,7 +117,7 @@ class ModelTest {
viewModel.updateCredentials(m2) viewModel.updateCredentials(m2)
assertEquals("device1", viewModel.sessionState.value?.deviceId) assertEquals("device1", viewModel.currentSession()?.deviceId)
assertEquals(3, viewModel.credentials.value!!.size) assertEquals(3, viewModel.credentials.value!!.size)
assertTrue(viewModel.credentials.value!!.find { it.credential == cred1 } != null) assertTrue(viewModel.credentials.value!!.find { it.credential == cred1 } != null)
assertTrue(viewModel.credentials.value!!.find { it.credential == cred2 } != null) assertTrue(viewModel.credentials.value!!.find { it.credential == cred2 } != null)
@ -388,9 +388,9 @@ class ModelTest {
val deviceId = "device" val deviceId = "device"
connectDevice(deviceId) connectDevice(deviceId)
viewModel.updateCredentials(mapOf(totp() to code())) viewModel.updateCredentials(mapOf(totp() to code()))
viewModel.setSessionState(null) viewModel.clearSession()
assertNull(viewModel.sessionState.value) assertEquals(ViewModelData.Empty, viewModel.sessionState.value)
assertNull(viewModel.credentials.value) assertNull(viewModel.credentials.value)
} }
} }

View File

@ -40,8 +40,7 @@ class SerializationTest {
Version(1, 2, 3), Version(1, 2, 3),
isAccessKeySet = false, isAccessKeySet = false,
isRemembered = false, isRemembered = false,
isLocked = false, isLocked = false
initialized = true
) )
@Test @Test