-
Notifications
You must be signed in to change notification settings - Fork 14
mini test for the "SaveInsuree" function #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Blue-B-code
wants to merge
8
commits into
openimis:develop
Choose a base branch
from
Y-Note-SAS:feature-34669
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+150
−8
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
43bee7c
fix officerCode is null on login
Blue-B-code e5cc263
corrections
Blue-B-code c5d0813
set test infra
Blue-B-code 83be681
testing the creation of a new insuree
Blue-B-code cdfc361
corrections
Blue-B-code 481a713
Update ExampleUnitTest.java
Blue-B-code 08e491f
improve tests logging
Blue-B-code 348a3a3
add pull_request on workflow
Blue-B-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
114 changes: 114 additions & 0 deletions
114
app/src/test/java/org/openimis/imispolicies/ClientAndroidInterfaceTest.java
This file contains hidden or 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,114 @@ | ||
| package org.openimis.imispolicies; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyInt; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.Mockito.*; | ||
| import com.squareup.picasso.Picasso; | ||
| import org.openimis.imispolicies.tools.StorageManager; | ||
| import org.robolectric.RobolectricTestRunner; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.res.Resources; | ||
|
|
||
| import org.json.JSONArray; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
| import org.mockito.junit.MockitoJUnitRunner; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| @RunWith(RobolectricTestRunner.class) | ||
| public class ClientAndroidInterfaceTest { | ||
|
|
||
| @Mock | ||
| SQLHandler sqlHandler; | ||
|
|
||
| @Mock | ||
| Global global; | ||
|
|
||
| @Mock | ||
| Activity activity; | ||
|
|
||
| @Mock | ||
| Resources resources; | ||
|
|
||
| @Mock | ||
| StorageManager storageManager; | ||
|
|
||
| ClientAndroidInterface client; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| MockitoAnnotations.openMocks(this); | ||
|
|
||
| when(activity.getResources()).thenReturn(resources); | ||
| when(resources.getString(anyInt())).thenReturn("mockString"); | ||
|
|
||
| client = new ClientAndroidInterface(activity, sqlHandler, global, null, storageManager); | ||
|
|
||
| when(global.isNetworkAvailable()).thenReturn(true); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateNewInsuree_ShouldInsertInDatabase() throws Exception { | ||
|
|
||
| String insureeJson = "{" | ||
| + "\"txtInsuranceNumber\":\"12345\"," | ||
| + "\"hfInsureeId\":\"0\"," | ||
| + "\"hfisHead\":\"1\"," | ||
| + "\"txtLastName\":\"Doe\"," | ||
| + "\"txtOtherNames\":\"John\"," | ||
| + "\"txtBirthDate\":\"1991-01-01\"," | ||
| + "\"ddlGender\":\"M\"," | ||
| + "\"txtPhoneNumber\":\"690000000\"" | ||
| + "\"hfNewPhotoPath\":\"\"" | ||
| + "\"hfImagePath\":\"/storage/emulated/0/DCIM/test.jpg\"" | ||
| + "}"; | ||
|
|
||
| ClientAndroidInterface spyClient = spy(client); | ||
|
|
||
| HashMap<String, String> mockData = new HashMap<>(); | ||
| mockData.put("txtInsuranceNumber", "12345"); | ||
| mockData.put("hfInsureeId", "0"); | ||
| mockData.put("hfisHead", "1"); | ||
| mockData.put("txtLastName", "Doe"); | ||
| mockData.put("txtOtherNames", "John"); | ||
| mockData.put("txtBirthDate", "1991-01-01"); | ||
| mockData.put("ddlGender", "M"); | ||
| mockData.put("txtPhoneNumber", "690000000"); | ||
| mockData.put("hfNewPhotoPath", ""); | ||
| mockData.put("hfImagePath", "/storage/emulated/0/DCIM/test.jpg"); | ||
|
|
||
| when(sqlHandler.getResult(anyString(), any(String[].class))).thenReturn(new JSONArray()); | ||
| doNothing().when(spyClient).SaveInsureePolicy(anyInt(), anyInt(), anyBoolean(), anyInt()); | ||
| doNothing().when(sqlHandler).insertData(anyString(), any()); | ||
| doNothing().when(sqlHandler).updateData(anyString(), any(), anyString(), any(String[].class)); | ||
| doReturn(mockData).when(spyClient).jsonToTable(anyString()); | ||
| doReturn(0).when(spyClient).isValidInsureeData(mockData); | ||
| doReturn(999).when(spyClient).getNextAvailableInsureeId(); | ||
| doReturn(0).when(spyClient).getFamilyStatus(anyInt()); | ||
| doReturn(0).when(spyClient).getInsureeStatus(anyInt()); | ||
| doNothing().when(spyClient).ShowDialog(anyString()); | ||
| doNothing().when(spyClient).ShowDialogYesNo(anyInt(), anyInt(), anyInt()); | ||
| doReturn("").when(spyClient).copyImageFromGalleryToApplication(anyString(), anyString()); | ||
|
|
||
| doNothing().when(sqlHandler).insertData(anyString(), any()); | ||
|
|
||
| int result = spyClient.SaveInsuree( | ||
| insureeJson, | ||
| 1, // FamilyId | ||
| 1, // isHead | ||
| 0, // ExceedThreshold | ||
| 0 // PolicyId | ||
| ); | ||
|
|
||
| assertEquals(-999, result); | ||
|
|
||
| verify(sqlHandler, times(1)).insertData(eq("tblInsuree"), any()); | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a quoi sert ceci?