@@ -121,6 +121,44 @@ class UID2ManagerTest {
121
121
assertManagerState(manager, null , NO_IDENTITY )
122
122
}
123
123
124
+ @Test
125
+ fun `reports when has identity` () = runTest(testDispatcher) {
126
+ // When the default identity is restored, verify that hasIdentity reflects this.
127
+ assertNotNull(manager.currentIdentity)
128
+ assertTrue(manager.hasIdentity())
129
+ }
130
+
131
+ @Test
132
+ fun `reports when no identity available` () = runTest(testDispatcher) {
133
+ // Reset the Manager's identity
134
+ manager.resetIdentity()
135
+ testDispatcher.scheduler.advanceUntilIdle()
136
+
137
+ // Verify that no identity is reported.
138
+ assertNull(manager.currentIdentity)
139
+ assertFalse(manager.hasIdentity())
140
+ }
141
+
142
+ @Test
143
+ fun `reports when no identity available after opt-out` () = runTest(testDispatcher) {
144
+ // Configure the client so that when asked to refresh, it actually reports that the user has now opted out.
145
+ whenever(client.refreshIdentity(initialIdentity.refreshToken, initialIdentity.refreshResponseKey)).thenReturn(
146
+ RefreshPackage (
147
+ null ,
148
+ OPT_OUT ,
149
+ " User opt-ed out" ,
150
+ ),
151
+ )
152
+
153
+ // Ask the manager to refresh, allowing the current TestDispatcher to process any jobs.
154
+ manager.refreshIdentity()
155
+ testDispatcher.scheduler.advanceUntilIdle()
156
+
157
+ // Verify that no identity is reported.
158
+ assertNull(manager.currentIdentity)
159
+ assertFalse(manager.hasIdentity())
160
+ }
161
+
124
162
@Test
125
163
fun `refresh no-op when no identity` () = runTest(testDispatcher) {
126
164
// Create a mock StorageManager that doesn't have any previously saved Identity.
0 commit comments