Replaces use of LoginType.value with name

This commit is contained in:
ericdecanini 2022-03-15 14:59:09 +01:00
parent ae540297b1
commit a173accfa5
4 changed files with 26 additions and 26 deletions

View file

@ -38,7 +38,7 @@ internal class SessionParamsMapper @Inject constructor(moshi: Moshi) {
if (credentials == null || homeServerConnectionConfig == null) { if (credentials == null || homeServerConnectionConfig == null) {
return 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? { fun map(sessionParams: SessionParams?): SessionParamsEntity? {
@ -56,7 +56,7 @@ internal class SessionParamsMapper @Inject constructor(moshi: Moshi) {
credentialsJson, credentialsJson,
homeServerConnectionConfigJson, homeServerConnectionConfigJson,
sessionParams.isTokenValid, sessionParams.isTokenValid,
sessionParams.loginType.value, sessionParams.loginType.name,
) )
} }
} }

View file

@ -16,22 +16,22 @@
package org.matrix.android.sdk.internal.auth.login package org.matrix.android.sdk.internal.auth.login
enum class LoginType(val value: String) { enum class LoginType {
PASSWORD("password"), PASSWORD,
SSO("sso"), SSO,
UNSUPPORTED("unsupported"), UNSUPPORTED,
CUSTOM("custom"), CUSTOM,
DIRECT("direct"), DIRECT,
UNKNOWN("unknown"); UNKNOWN;
companion object { companion object {
fun fromValue(value: String) = when (value) { fun fromName(name: String) = when (name) {
PASSWORD.value -> PASSWORD PASSWORD.name -> PASSWORD
SSO.value -> SSO SSO.name -> SSO
UNSUPPORTED.value -> UNSUPPORTED UNSUPPORTED.name -> UNSUPPORTED
CUSTOM.value -> CUSTOM CUSTOM.name -> CUSTOM
DIRECT.value -> DIRECT DIRECT.name -> DIRECT
else -> UNKNOWN else -> UNKNOWN
} }
} }

View file

@ -23,22 +23,22 @@ import org.junit.Test
class LoginTypeTest { class LoginTypeTest {
@Test @Test
fun `when getting type fromValue, then map correctly`() { fun `when getting type fromName, then map correctly`() {
LoginType.fromValue(LoginType.PASSWORD.value) shouldBeEqualTo LoginType.PASSWORD LoginType.fromName(LoginType.PASSWORD.name) shouldBeEqualTo LoginType.PASSWORD
LoginType.fromValue(LoginType.SSO.value) shouldBeEqualTo LoginType.SSO LoginType.fromName(LoginType.SSO.name) shouldBeEqualTo LoginType.SSO
LoginType.fromValue(LoginType.UNSUPPORTED.value) shouldBeEqualTo LoginType.UNSUPPORTED LoginType.fromName(LoginType.UNSUPPORTED.name) shouldBeEqualTo LoginType.UNSUPPORTED
LoginType.fromValue(LoginType.CUSTOM.value) shouldBeEqualTo LoginType.CUSTOM LoginType.fromName(LoginType.CUSTOM.name) shouldBeEqualTo LoginType.CUSTOM
LoginType.fromValue(LoginType.DIRECT.value) shouldBeEqualTo LoginType.DIRECT LoginType.fromName(LoginType.DIRECT.name) shouldBeEqualTo LoginType.DIRECT
LoginType.fromValue(LoginType.UNKNOWN.value) shouldBeEqualTo LoginType.UNKNOWN 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 @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() val types = LoginType.values()
types.forEach { type -> types.forEach { type ->
if (type != LoginType.UNKNOWN) { if (type != LoginType.UNKNOWN) {
LoginType.fromValue(type.value) shouldNotBeEqualTo LoginType.UNKNOWN LoginType.fromName(type.name) shouldNotBeEqualTo LoginType.UNKNOWN
} }
} }
} }

View file

@ -54,7 +54,7 @@ internal class FakeSessionParamsMapperMoshi {
credentials, credentials,
homeServerConnectionConfig, homeServerConnectionConfig,
sessionParamsEntity.isTokenValid, sessionParamsEntity.isTokenValid,
LoginType.fromValue(sessionParamsEntity.loginType) LoginType.fromName(sessionParamsEntity.loginType)
) )
} }
@ -69,7 +69,7 @@ internal class FakeSessionParamsMapperMoshi {
CREDENTIALS_JSON, CREDENTIALS_JSON,
HOME_SERVER_CONNECTION_CONFIG_JSON, HOME_SERVER_CONNECTION_CONFIG_JSON,
sessionParams.isTokenValid, sessionParams.isTokenValid,
sessionParams.loginType.value, sessionParams.loginType.name,
) )
} }