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 a5f6ebd2f8..635ecc7658 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 @@ -19,6 +19,7 @@ package org.matrix.android.sdk.internal.auth.login enum class LoginType(val value: String) { PASSWORD("password"), SSO("sso"), + UNSUPPORTED("unsupported"), UNKNOWN("unknown"); companion object { @@ -26,6 +27,7 @@ enum class LoginType(val value: String) { fun fromValue(value: String) = when (value) { PASSWORD.value -> PASSWORD SSO.value -> SSO + UNSUPPORTED.value -> UNSUPPORTED 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 new file mode 100644 index 0000000000..c52dd4fe67 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/auth/login/LoginTypeTest.kt @@ -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 + } + } +}