1- /*
2- * Copyright 2025 Google Inc. All Rights Reserved.
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5- * in compliance with the License. You may obtain a copy of the License at
6- *
7- * http://www.apache.org/licenses/LICENSE-2.0
8- *
9- * Unless required by applicable law or agreed to in writing, software distributed under the
10- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11- * express or implied. See the License for the specific language governing permissions and
12- * limitations under the License.
13- */
14-
15- package com.firebase.ui.auth.compose
1+ package com.firebase.ui.auth.compose.ui.components
162
3+ import com.firebase.ui.auth.compose.AuthException
174import com.firebase.ui.auth.compose.configuration.string_provider.AuthUIStringProvider
18- import com.google.common.truth.Truth.assertThat
5+ import com.google.common.truth.Truth
196import org.junit.Test
207import org.junit.runner.RunWith
21- import org.mockito.Mockito.mock
22- import org.mockito.Mockito.`when`
8+ import org.mockito.Mockito
239import org.robolectric.RobolectricTestRunner
2410import org.robolectric.annotation.Config
2511
2612/* *
27- * Unit tests for [com.firebase.ui.auth.compose.ui.components. ErrorRecoveryDialog] logic functions.
13+ * Unit tests for [ErrorRecoveryDialog] logic functions.
2814 */
2915@RunWith(RobolectricTestRunner ::class )
3016@Config(manifest = Config .NONE )
3117class ErrorRecoveryDialogLogicTest {
3218
33- private val mockStringProvider = mock(AuthUIStringProvider ::class .java).apply {
34- `when `(retryAction).thenReturn(" Try again" )
35- `when `(continueText).thenReturn(" Continue" )
36- `when `(signInDefault).thenReturn(" Sign in" )
37- `when `(networkErrorRecoveryMessage).thenReturn(" Network error, check your internet connection." )
38- `when `(invalidCredentialsRecoveryMessage).thenReturn(" Incorrect password." )
39- `when `(userNotFoundRecoveryMessage).thenReturn(" That email address doesn't match an existing account" )
40- `when `(weakPasswordRecoveryMessage).thenReturn(" Password not strong enough. Use at least 6 characters and a mix of letters and numbers" )
41- `when `(emailAlreadyInUseRecoveryMessage).thenReturn(" Email account registration unsuccessful" )
42- `when `(tooManyRequestsRecoveryMessage).thenReturn(" This phone number has been used too many times" )
43- `when `(mfaRequiredRecoveryMessage).thenReturn(" Additional verification required. Please complete multi-factor authentication." )
44- `when `(accountLinkingRequiredRecoveryMessage).thenReturn(" Account needs to be linked. Please try a different sign-in method." )
45- `when `(authCancelledRecoveryMessage).thenReturn(" Authentication was cancelled. Please try again when ready." )
46- `when `(unknownErrorRecoveryMessage).thenReturn(" An unknown error occurred." )
19+ private val mockStringProvider = Mockito . mock(AuthUIStringProvider ::class .java).apply {
20+ Mockito . `when `(retryAction).thenReturn(" Try again" )
21+ Mockito . `when `(continueText).thenReturn(" Continue" )
22+ Mockito . `when `(signInDefault).thenReturn(" Sign in" )
23+ Mockito . `when `(networkErrorRecoveryMessage).thenReturn(" Network error, check your internet connection." )
24+ Mockito . `when `(invalidCredentialsRecoveryMessage).thenReturn(" Incorrect password." )
25+ Mockito . `when `(userNotFoundRecoveryMessage).thenReturn(" That email address doesn't match an existing account" )
26+ Mockito . `when `(weakPasswordRecoveryMessage).thenReturn(" Password not strong enough. Use at least 6 characters and a mix of letters and numbers" )
27+ Mockito . `when `(emailAlreadyInUseRecoveryMessage).thenReturn(" Email account registration unsuccessful" )
28+ Mockito . `when `(tooManyRequestsRecoveryMessage).thenReturn(" This phone number has been used too many times" )
29+ Mockito . `when `(mfaRequiredRecoveryMessage).thenReturn(" Additional verification required. Please complete multi-factor authentication." )
30+ Mockito . `when `(accountLinkingRequiredRecoveryMessage).thenReturn(" Account needs to be linked. Please try a different sign-in method." )
31+ Mockito . `when `(authCancelledRecoveryMessage).thenReturn(" Authentication was cancelled. Please try again when ready." )
32+ Mockito . `when `(unknownErrorRecoveryMessage).thenReturn(" An unknown error occurred." )
4733 }
4834
4935 // =============================================================================================
@@ -59,7 +45,7 @@ class ErrorRecoveryDialogLogicTest {
5945 val message = getRecoveryMessage(error, mockStringProvider)
6046
6147 // Assert
62- assertThat(message).isEqualTo(" Network error, check your internet connection." )
48+ Truth . assertThat(message).isEqualTo(" Network error, check your internet connection." )
6349 }
6450
6551 @Test
@@ -71,7 +57,7 @@ class ErrorRecoveryDialogLogicTest {
7157 val message = getRecoveryMessage(error, mockStringProvider)
7258
7359 // Assert
74- assertThat(message).isEqualTo(" Incorrect password." )
60+ Truth . assertThat(message).isEqualTo(" Incorrect password." )
7561 }
7662
7763 @Test
@@ -83,7 +69,7 @@ class ErrorRecoveryDialogLogicTest {
8369 val message = getRecoveryMessage(error, mockStringProvider)
8470
8571 // Assert
86- assertThat(message).isEqualTo(" That email address doesn't match an existing account" )
72+ Truth . assertThat(message).isEqualTo(" That email address doesn't match an existing account" )
8773 }
8874
8975 @Test
@@ -99,7 +85,7 @@ class ErrorRecoveryDialogLogicTest {
9985 val message = getRecoveryMessage(error, mockStringProvider)
10086
10187 // Assert
102- assertThat(message).isEqualTo(" Password not strong enough. Use at least 6 characters and a mix of letters and numbers\n\n Reason: Password should be at least 8 characters" )
88+ Truth . assertThat(message).isEqualTo(" Password not strong enough. Use at least 6 characters and a mix of letters and numbers\n\n Reason: Password should be at least 8 characters" )
10389 }
10490
10591 @Test
@@ -111,7 +97,7 @@ class ErrorRecoveryDialogLogicTest {
11197 val message = getRecoveryMessage(error, mockStringProvider)
11298
11399 // Assert
114- assertThat(message).isEqualTo(" Password not strong enough. Use at least 6 characters and a mix of letters and numbers" )
100+ Truth . assertThat(message).isEqualTo(" Password not strong enough. Use at least 6 characters and a mix of letters and numbers" )
115101 }
116102
117103 @Test
@@ -127,7 +113,7 @@ class ErrorRecoveryDialogLogicTest {
127113 val message = getRecoveryMessage(error, mockStringProvider)
128114
129115 // Assert
130- assertThat(message).isEqualTo(" Email account registration unsuccessful (test@example.com)" )
116+ Truth . assertThat(message).isEqualTo(" Email account registration unsuccessful (test@example.com)" )
131117 }
132118
133119 @Test
@@ -139,7 +125,7 @@ class ErrorRecoveryDialogLogicTest {
139125 val message = getRecoveryMessage(error, mockStringProvider)
140126
141127 // Assert
142- assertThat(message).isEqualTo(" Email account registration unsuccessful" )
128+ Truth . assertThat(message).isEqualTo(" Email account registration unsuccessful" )
143129 }
144130
145131 // =============================================================================================
@@ -155,7 +141,7 @@ class ErrorRecoveryDialogLogicTest {
155141 val actionText = getRecoveryActionText(error, mockStringProvider)
156142
157143 // Assert
158- assertThat(actionText).isEqualTo(" Try again" )
144+ Truth . assertThat(actionText).isEqualTo(" Try again" )
159145 }
160146
161147 @Test
@@ -167,7 +153,7 @@ class ErrorRecoveryDialogLogicTest {
167153 val actionText = getRecoveryActionText(error, mockStringProvider)
168154
169155 // Assert
170- assertThat(actionText).isEqualTo(" Continue" )
156+ Truth . assertThat(actionText).isEqualTo(" Continue" )
171157 }
172158
173159 @Test
@@ -179,7 +165,7 @@ class ErrorRecoveryDialogLogicTest {
179165 val actionText = getRecoveryActionText(error, mockStringProvider)
180166
181167 // Assert
182- assertThat(actionText).isEqualTo(" Sign in" )
168+ Truth . assertThat(actionText).isEqualTo(" Sign in" )
183169 }
184170
185171 @Test
@@ -191,7 +177,7 @@ class ErrorRecoveryDialogLogicTest {
191177 val actionText = getRecoveryActionText(error, mockStringProvider)
192178
193179 // Assert
194- assertThat(actionText).isEqualTo(" Continue" )
180+ Truth . assertThat(actionText).isEqualTo(" Continue" )
195181 }
196182
197183 @Test
@@ -203,7 +189,7 @@ class ErrorRecoveryDialogLogicTest {
203189 val actionText = getRecoveryActionText(error, mockStringProvider)
204190
205191 // Assert
206- assertThat(actionText).isEqualTo(" Continue" )
192+ Truth . assertThat(actionText).isEqualTo(" Continue" )
207193 }
208194
209195 // =============================================================================================
@@ -216,7 +202,7 @@ class ErrorRecoveryDialogLogicTest {
216202 val error = AuthException .NetworkException (" Network error" )
217203
218204 // Act & Assert
219- assertThat(isRecoverable(error)).isTrue()
205+ Truth . assertThat(isRecoverable(error)).isTrue()
220206 }
221207
222208 @Test
@@ -225,7 +211,7 @@ class ErrorRecoveryDialogLogicTest {
225211 val error = AuthException .InvalidCredentialsException (" Invalid credentials" )
226212
227213 // Act & Assert
228- assertThat(isRecoverable(error)).isTrue()
214+ Truth . assertThat(isRecoverable(error)).isTrue()
229215 }
230216
231217 @Test
@@ -234,7 +220,7 @@ class ErrorRecoveryDialogLogicTest {
234220 val error = AuthException .TooManyRequestsException (" Too many requests" )
235221
236222 // Act & Assert
237- assertThat(isRecoverable(error)).isFalse()
223+ Truth . assertThat(isRecoverable(error)).isFalse()
238224 }
239225
240226 @Test
@@ -243,7 +229,7 @@ class ErrorRecoveryDialogLogicTest {
243229 val error = AuthException .MfaRequiredException (" MFA required" )
244230
245231 // Act & Assert
246- assertThat(isRecoverable(error)).isTrue()
232+ Truth . assertThat(isRecoverable(error)).isTrue()
247233 }
248234
249235 @Test
@@ -252,7 +238,7 @@ class ErrorRecoveryDialogLogicTest {
252238 val error = AuthException .UnknownException (" Unknown error" )
253239
254240 // Act & Assert
255- assertThat(isRecoverable(error)).isTrue()
241+ Truth . assertThat(isRecoverable(error)).isTrue()
256242 }
257243
258244 // Helper functions to test the private functions - we need to make them internal for testing
0 commit comments