Adds loginType UNSUPPORTED

This commit is contained in:
ericdecanini 2022-03-04 14:24:47 +01:00
parent ea53462107
commit 32bde5a344
2 changed files with 44 additions and 0 deletions

View file

@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.auth.login
enum class LoginType(val value: String) { enum class LoginType(val value: String) {
PASSWORD("password"), PASSWORD("password"),
SSO("sso"), SSO("sso"),
UNSUPPORTED("unsupported"),
UNKNOWN("unknown"); UNKNOWN("unknown");
companion object { companion object {
@ -26,6 +27,7 @@ enum class LoginType(val value: String) {
fun fromValue(value: String) = when (value) { fun fromValue(value: String) = when (value) {
PASSWORD.value -> PASSWORD PASSWORD.value -> PASSWORD
SSO.value -> SSO SSO.value -> SSO
UNSUPPORTED.value -> UNSUPPORTED
else -> UNKNOWN else -> UNKNOWN
} }
} }

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth.login
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldNotBeEqualTo
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.UNKNOWN.value) shouldBeEqualTo LoginType.UNKNOWN
}
@Test // This test failing means 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`() {
val types = LoginType.values()
types.forEach { type ->
if (type != LoginType.UNKNOWN)
LoginType.fromValue(type.value) shouldNotBeEqualTo LoginType.UNKNOWN
}
}
}