|
31 | 31 | import org.smartregister.domain.jsonmapping.util.TeamMember;
|
32 | 32 | import org.smartregister.receiver.SyncStatusBroadcastReceiver;
|
33 | 33 | import org.smartregister.repository.AllSharedPreferences;
|
| 34 | +import org.smartregister.service.UserService; |
34 | 35 |
|
35 | 36 | import java.text.SimpleDateFormat;
|
36 | 37 | import java.util.ArrayList;
|
|
46 | 47 | import static org.junit.Assert.assertNotNull;
|
47 | 48 | import static org.junit.Assert.assertNull;
|
48 | 49 | import static org.junit.Assert.assertTrue;
|
| 50 | +import static org.mockito.ArgumentMatchers.any; |
| 51 | +import static org.mockito.ArgumentMatchers.anyString; |
| 52 | +import static org.mockito.Mockito.doReturn; |
| 53 | +import static org.mockito.Mockito.mock; |
| 54 | +import static org.mockito.Mockito.spy; |
| 55 | +import static org.mockito.Mockito.times; |
| 56 | +import static org.mockito.Mockito.verify; |
49 | 57 | import static org.smartregister.TestUtils.getContext;
|
50 | 58 | import static org.smartregister.util.Utils.getDefaultLocale;
|
51 | 59 |
|
@@ -449,5 +457,18 @@ public void testGetAppIdShouldReturnAppId() {
|
449 | 457 | public void testGetAppVersionShouldReturnAppVersion() {
|
450 | 458 | assertNull(Utils.getAppVersion(RuntimeEnvironment.application));
|
451 | 459 | }
|
| 460 | + |
| 461 | + @Test |
| 462 | + public void testLogoutUserShouldInvokeRequiredMethods() { |
| 463 | + org.smartregister.Context opensrpContext = spy(CoreLibrary.getInstance().context()); |
| 464 | + Context context = spy(opensrpContext.applicationContext()); |
| 465 | + doReturn(context).when(opensrpContext).applicationContext(); |
| 466 | + UserService mockUserService = mock(UserService.class); |
| 467 | + doReturn(mockUserService).when(opensrpContext).userService(); |
| 468 | + Utils.logoutUser(opensrpContext, "logged out"); |
| 469 | + verify(mockUserService, times(1)).forceRemoteLogin(anyString()); |
| 470 | + verify(mockUserService, times(1)).logoutSession(); |
| 471 | + verify(context, times(1)).startActivity(any(Intent.class)); |
| 472 | + } |
452 | 473 | }
|
453 | 474 |
|
0 commit comments