-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #743 from OpenSRP/kigamba-tt-09-02-2021
Add Utils and SyncUtils tests
- Loading branch information
Showing
5 changed files
with
158 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DRISHTI_BASE_URL= | ||
PORT=-1 | ||
SHOULD_VERIFY_CERTIFICATE=false | ||
SYNC_DOWNLOAD_BATCH_SIZE=10 | ||
system.toaster.centered=false |
77 changes: 77 additions & 0 deletions
77
opensrp-app/src/test/java/org/smartregister/util/SyncUtilsRobolectricTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.smartregister.util; | ||
|
||
import android.accounts.AuthenticatorException; | ||
import android.accounts.OperationCanceledException; | ||
import android.content.Intent; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mockito; | ||
import org.robolectric.RuntimeEnvironment; | ||
import org.robolectric.util.ReflectionHelpers; | ||
import org.smartregister.BaseRobolectricUnitTest; | ||
import org.smartregister.Context; | ||
import org.smartregister.CoreLibrary; | ||
import org.smartregister.R; | ||
import org.smartregister.service.UserService; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
/** | ||
* Created by Ephraim Kigamba - [email protected] on 09-02-2021. | ||
*/ | ||
public class SyncUtilsRobolectricTest extends BaseRobolectricUnitTest { | ||
|
||
private SyncUtils syncUtils; | ||
private android.content.Context context; | ||
private UserService userService; | ||
|
||
@Before | ||
public void setUp() { | ||
Context opensrpContext = Mockito.spy(CoreLibrary.getInstance().context()); | ||
userService = Mockito.spy(opensrpContext.userService()); | ||
Mockito.doReturn(userService).when(opensrpContext).userService(); | ||
|
||
context = Mockito.spy(RuntimeEnvironment.application); | ||
|
||
syncUtils = new SyncUtils(context); | ||
ReflectionHelpers.setField(syncUtils, "opensrpContext", opensrpContext); | ||
} | ||
|
||
@Ignore | ||
@Test | ||
public void logoutUser() throws AuthenticatorException, OperationCanceledException, IOException { | ||
ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); | ||
Mockito.doNothing().when(context).startActivity(intentArgumentCaptor.capture()); | ||
|
||
syncUtils.logoutUser(R.string.logout_text); | ||
|
||
Mockito.verify(userService).forceRemoteLogin(Mockito.anyString()); | ||
Mockito.verify(userService).logoutSession(); | ||
|
||
Intent intent = intentArgumentCaptor.getValue(); | ||
Assert.assertEquals(Intent.ACTION_MAIN, intent.getAction()); | ||
Assert.assertTrue(intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)); | ||
Assert.assertEquals("org.smartregister", intent.getPackage()); | ||
|
||
Mockito.verify(context).startActivity(Mockito.any(Intent.class)); | ||
|
||
} | ||
|
||
@Test | ||
public void getLogoutUserIntentShouldProvideAnonymouseIntentWhenLauncherActivityIsUnavailable() { | ||
ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); | ||
Mockito.doNothing().when(context).startActivity(intentArgumentCaptor.capture()); | ||
|
||
Intent intent = syncUtils.getLogoutUserIntent(R.string.logout_text); | ||
|
||
Assert.assertEquals(Intent.ACTION_MAIN, intent.getAction()); | ||
Assert.assertTrue(intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)); | ||
Assert.assertEquals("org.smartregister.test", intent.getPackage()); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters