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
16
2
3
+ import com.firebase.ui.auth.compose.AuthException
17
4
import com.firebase.ui.auth.compose.configuration.string_provider.AuthUIStringProvider
18
- import com.google.common.truth.Truth.assertThat
5
+ import com.google.common.truth.Truth
19
6
import org.junit.Test
20
7
import org.junit.runner.RunWith
21
- import org.mockito.Mockito.mock
22
- import org.mockito.Mockito.`when`
8
+ import org.mockito.Mockito
23
9
import org.robolectric.RobolectricTestRunner
24
10
import org.robolectric.annotation.Config
25
11
26
12
/* *
27
- * Unit tests for [com.firebase.ui.auth.compose.ui.components. ErrorRecoveryDialog] logic functions.
13
+ * Unit tests for [ErrorRecoveryDialog] logic functions.
28
14
*/
29
15
@RunWith(RobolectricTestRunner ::class )
30
16
@Config(manifest = Config .NONE )
31
17
class ErrorRecoveryDialogLogicTest {
32
18
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." )
47
33
}
48
34
49
35
// =============================================================================================
@@ -59,7 +45,7 @@ class ErrorRecoveryDialogLogicTest {
59
45
val message = getRecoveryMessage(error, mockStringProvider)
60
46
61
47
// Assert
62
- assertThat(message).isEqualTo(" Network error, check your internet connection." )
48
+ Truth . assertThat(message).isEqualTo(" Network error, check your internet connection." )
63
49
}
64
50
65
51
@Test
@@ -71,7 +57,7 @@ class ErrorRecoveryDialogLogicTest {
71
57
val message = getRecoveryMessage(error, mockStringProvider)
72
58
73
59
// Assert
74
- assertThat(message).isEqualTo(" Incorrect password." )
60
+ Truth . assertThat(message).isEqualTo(" Incorrect password." )
75
61
}
76
62
77
63
@Test
@@ -83,7 +69,7 @@ class ErrorRecoveryDialogLogicTest {
83
69
val message = getRecoveryMessage(error, mockStringProvider)
84
70
85
71
// 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" )
87
73
}
88
74
89
75
@Test
@@ -99,7 +85,7 @@ class ErrorRecoveryDialogLogicTest {
99
85
val message = getRecoveryMessage(error, mockStringProvider)
100
86
101
87
// 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" )
103
89
}
104
90
105
91
@Test
@@ -111,7 +97,7 @@ class ErrorRecoveryDialogLogicTest {
111
97
val message = getRecoveryMessage(error, mockStringProvider)
112
98
113
99
// 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" )
115
101
}
116
102
117
103
@Test
@@ -127,7 +113,7 @@ class ErrorRecoveryDialogLogicTest {
127
113
val message = getRecoveryMessage(error, mockStringProvider)
128
114
129
115
// Assert
130
- assertThat(message).isEqualTo(
" Email account registration unsuccessful ([email protected] )" )
116
+ Truth . assertThat(message).isEqualTo(
" Email account registration unsuccessful ([email protected] )" )
131
117
}
132
118
133
119
@Test
@@ -139,7 +125,7 @@ class ErrorRecoveryDialogLogicTest {
139
125
val message = getRecoveryMessage(error, mockStringProvider)
140
126
141
127
// Assert
142
- assertThat(message).isEqualTo(" Email account registration unsuccessful" )
128
+ Truth . assertThat(message).isEqualTo(" Email account registration unsuccessful" )
143
129
}
144
130
145
131
// =============================================================================================
@@ -155,7 +141,7 @@ class ErrorRecoveryDialogLogicTest {
155
141
val actionText = getRecoveryActionText(error, mockStringProvider)
156
142
157
143
// Assert
158
- assertThat(actionText).isEqualTo(" Try again" )
144
+ Truth . assertThat(actionText).isEqualTo(" Try again" )
159
145
}
160
146
161
147
@Test
@@ -167,7 +153,7 @@ class ErrorRecoveryDialogLogicTest {
167
153
val actionText = getRecoveryActionText(error, mockStringProvider)
168
154
169
155
// Assert
170
- assertThat(actionText).isEqualTo(" Continue" )
156
+ Truth . assertThat(actionText).isEqualTo(" Continue" )
171
157
}
172
158
173
159
@Test
@@ -179,7 +165,7 @@ class ErrorRecoveryDialogLogicTest {
179
165
val actionText = getRecoveryActionText(error, mockStringProvider)
180
166
181
167
// Assert
182
- assertThat(actionText).isEqualTo(" Sign in" )
168
+ Truth . assertThat(actionText).isEqualTo(" Sign in" )
183
169
}
184
170
185
171
@Test
@@ -191,7 +177,7 @@ class ErrorRecoveryDialogLogicTest {
191
177
val actionText = getRecoveryActionText(error, mockStringProvider)
192
178
193
179
// Assert
194
- assertThat(actionText).isEqualTo(" Continue" )
180
+ Truth . assertThat(actionText).isEqualTo(" Continue" )
195
181
}
196
182
197
183
@Test
@@ -203,7 +189,7 @@ class ErrorRecoveryDialogLogicTest {
203
189
val actionText = getRecoveryActionText(error, mockStringProvider)
204
190
205
191
// Assert
206
- assertThat(actionText).isEqualTo(" Continue" )
192
+ Truth . assertThat(actionText).isEqualTo(" Continue" )
207
193
}
208
194
209
195
// =============================================================================================
@@ -216,7 +202,7 @@ class ErrorRecoveryDialogLogicTest {
216
202
val error = AuthException .NetworkException (" Network error" )
217
203
218
204
// Act & Assert
219
- assertThat(isRecoverable(error)).isTrue()
205
+ Truth . assertThat(isRecoverable(error)).isTrue()
220
206
}
221
207
222
208
@Test
@@ -225,7 +211,7 @@ class ErrorRecoveryDialogLogicTest {
225
211
val error = AuthException .InvalidCredentialsException (" Invalid credentials" )
226
212
227
213
// Act & Assert
228
- assertThat(isRecoverable(error)).isTrue()
214
+ Truth . assertThat(isRecoverable(error)).isTrue()
229
215
}
230
216
231
217
@Test
@@ -234,7 +220,7 @@ class ErrorRecoveryDialogLogicTest {
234
220
val error = AuthException .TooManyRequestsException (" Too many requests" )
235
221
236
222
// Act & Assert
237
- assertThat(isRecoverable(error)).isFalse()
223
+ Truth . assertThat(isRecoverable(error)).isFalse()
238
224
}
239
225
240
226
@Test
@@ -243,7 +229,7 @@ class ErrorRecoveryDialogLogicTest {
243
229
val error = AuthException .MfaRequiredException (" MFA required" )
244
230
245
231
// Act & Assert
246
- assertThat(isRecoverable(error)).isTrue()
232
+ Truth . assertThat(isRecoverable(error)).isTrue()
247
233
}
248
234
249
235
@Test
@@ -252,7 +238,7 @@ class ErrorRecoveryDialogLogicTest {
252
238
val error = AuthException .UnknownException (" Unknown error" )
253
239
254
240
// Act & Assert
255
- assertThat(isRecoverable(error)).isTrue()
241
+ Truth . assertThat(isRecoverable(error)).isTrue()
256
242
}
257
243
258
244
// Helper functions to test the private functions - we need to make them internal for testing
0 commit comments