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) {
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,
)
}
}

View File

@ -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
}
}

View File

@ -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
}
}
}

View File

@ -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,
)
}