diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/db/SessionParamsMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/db/SessionParamsMapper.kt index e359577ff3..20de72dc8f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/db/SessionParamsMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/db/SessionParamsMapper.kt @@ -38,7 +38,7 @@ internal class SessionParamsMapper @Inject constructor(moshi: Moshi) { if (credentials == null || homeServerConnectionConfig == null) { return null } - return SessionParams(credentials, homeServerConnectionConfig, entity.isTokenValid, LoginType.fromValue(entity.loginType)) + return SessionParams(credentials, homeServerConnectionConfig, entity.isTokenValid, LoginType.fromName(entity.loginType)) } fun map(sessionParams: SessionParams?): SessionParamsEntity? { @@ -56,7 +56,7 @@ internal class SessionParamsMapper @Inject constructor(moshi: Moshi) { credentialsJson, homeServerConnectionConfigJson, sessionParams.isTokenValid, - sessionParams.loginType.value, + sessionParams.loginType.name, ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/LoginType.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/LoginType.kt index 31d8b01d38..5bc38d81fc 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/LoginType.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/auth/login/LoginType.kt @@ -16,22 +16,22 @@ package org.matrix.android.sdk.internal.auth.login -enum class LoginType(val value: String) { - PASSWORD("password"), - SSO("sso"), - UNSUPPORTED("unsupported"), - CUSTOM("custom"), - DIRECT("direct"), - UNKNOWN("unknown"); +enum class LoginType { + PASSWORD, + SSO, + UNSUPPORTED, + CUSTOM, + DIRECT, + UNKNOWN; companion object { - fun fromValue(value: String) = when (value) { - PASSWORD.value -> PASSWORD - SSO.value -> SSO - UNSUPPORTED.value -> UNSUPPORTED - CUSTOM.value -> CUSTOM - DIRECT.value -> DIRECT + fun fromName(name: String) = when (name) { + PASSWORD.name -> PASSWORD + SSO.name -> SSO + UNSUPPORTED.name -> UNSUPPORTED + CUSTOM.name -> CUSTOM + DIRECT.name -> DIRECT else -> UNKNOWN } } diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/login/LoginTypeTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/login/LoginTypeTest.kt index 1650c863de..341d09765c 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/login/LoginTypeTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/login/LoginTypeTest.kt @@ -23,22 +23,22 @@ import org.junit.Test class LoginTypeTest { @Test - fun `when getting type fromValue, then map correctly`() { - LoginType.fromValue(LoginType.PASSWORD.value) shouldBeEqualTo LoginType.PASSWORD - LoginType.fromValue(LoginType.SSO.value) shouldBeEqualTo LoginType.SSO - LoginType.fromValue(LoginType.UNSUPPORTED.value) shouldBeEqualTo LoginType.UNSUPPORTED - LoginType.fromValue(LoginType.CUSTOM.value) shouldBeEqualTo LoginType.CUSTOM - LoginType.fromValue(LoginType.DIRECT.value) shouldBeEqualTo LoginType.DIRECT - LoginType.fromValue(LoginType.UNKNOWN.value) shouldBeEqualTo LoginType.UNKNOWN + fun `when getting type fromName, then map correctly`() { + LoginType.fromName(LoginType.PASSWORD.name) shouldBeEqualTo LoginType.PASSWORD + LoginType.fromName(LoginType.SSO.name) shouldBeEqualTo LoginType.SSO + LoginType.fromName(LoginType.UNSUPPORTED.name) shouldBeEqualTo LoginType.UNSUPPORTED + LoginType.fromName(LoginType.CUSTOM.name) shouldBeEqualTo LoginType.CUSTOM + LoginType.fromName(LoginType.DIRECT.name) shouldBeEqualTo LoginType.DIRECT + LoginType.fromName(LoginType.UNKNOWN.name) shouldBeEqualTo LoginType.UNKNOWN } @Test // The failure of this test means that an existing type has not been correctly added to fromValue - fun `given non-unknown type value, when getting type fromValue, then type is not UNKNOWN`() { + fun `given non-unknown type name, when getting type fromName, then type is not UNKNOWN`() { val types = LoginType.values() types.forEach { type -> if (type != LoginType.UNKNOWN) { - LoginType.fromValue(type.value) shouldNotBeEqualTo LoginType.UNKNOWN + LoginType.fromName(type.name) shouldNotBeEqualTo LoginType.UNKNOWN } } } diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/internal/auth/db/sessionparams/FakeSessionParamsMapperMoshi.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/internal/auth/db/sessionparams/FakeSessionParamsMapperMoshi.kt index 62b7f9fc20..bc5a2fa7ca 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/internal/auth/db/sessionparams/FakeSessionParamsMapperMoshi.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/internal/auth/db/sessionparams/FakeSessionParamsMapperMoshi.kt @@ -54,7 +54,7 @@ internal class FakeSessionParamsMapperMoshi { credentials, homeServerConnectionConfig, sessionParamsEntity.isTokenValid, - LoginType.fromValue(sessionParamsEntity.loginType) + LoginType.fromName(sessionParamsEntity.loginType) ) } @@ -69,7 +69,7 @@ internal class FakeSessionParamsMapperMoshi { CREDENTIALS_JSON, HOME_SERVER_CONNECTION_CONFIG_JSON, sessionParams.isTokenValid, - sessionParams.loginType.value, + sessionParams.loginType.name, ) }