Skip to content

Commit c4030af

Browse files
authored
Merge pull request #117 from Y-Note-SAS/feature-35233
Unit tests for Insuree Inquiry
2 parents ed3e561 + 7a383c0 commit c4030af

File tree

8 files changed

+764
-103
lines changed

8 files changed

+764
-103
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ proguard/
2626
# Log Files
2727
*.log
2828

29+
# Java heap dump files
30+
*.hprof
31+
2932
# Android Studio Navigation editor temp files
3033
.navigation/
3134

claimManagement/src/main/java/org/openimis/imisclaims/ClaimActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
712712
}
713713
}
714714

715-
private boolean isValidData() {
715+
protected boolean isValidData() {
716716

717717
if (etHealthFacility.getText().length() == 0) {
718718
showValidationDialog(etHealthFacility, getResources().getString(R.string.MissingHealthFacility));
@@ -793,7 +793,7 @@ private boolean isValidData() {
793793
return true;
794794
}
795795

796-
private boolean isValidInsureeNumber() {
796+
protected boolean isValidInsureeNumber() {
797797
Escape escape = new Escape();
798798
return escape.CheckCHFID(etInsureeNumber.getText().toString());
799799
}

claimManagement/src/main/java/org/openimis/imisclaims/EnquireActivity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected AlertDialog ShowDialog(final TextView tv, String msg) {
201201

202202
@SuppressLint({"WrongConstant", "Range"})
203203
@Nullable
204-
private Insuree getDataFromDb(String chfid) {
204+
protected Insuree getDataFromDb(String chfid) {
205205
try {
206206
SQLiteDatabase db = openOrCreateDatabase(SQLHandler.DB_NAME_DATA, SQLiteDatabase.OPEN_READONLY, null);
207207
String[] columns = {"CHFID", "Photo", "InsureeName", "DOB", "Gender", "ProductCode", "ProductName", "ExpiryDate", "Status", "DedType", "Ded1", "Ded2", "Ceiling1", "Ceiling2"};
@@ -271,13 +271,22 @@ private Insuree getDataFromDb(String chfid) {
271271

272272
}
273273

274+
protected Insuree createFetchInsureeInquire(String chfid) {
275+
try {
276+
return new FetchInsureeInquire().execute(chfid);
277+
} catch (Exception e) {
278+
Log.e(LOG_TAG, "Fetching online enquire failed", e);
279+
return null;
280+
}
281+
}
282+
274283
@WorkerThread
275-
private void getInsureeInfo() {
284+
protected void getInsureeInfo() {
276285
runOnUiThread(this::ClearForm);
277286
String chfid = etCHFID.getText().toString();
278287
if (global.isNetworkAvailable()) {
279288
try {
280-
Insuree insuree = new FetchInsureeInquire().execute(chfid);
289+
Insuree insuree = createFetchInsureeInquire(chfid);
281290
runOnUiThread(() -> renderResult(insuree));
282291
} catch (HttpException e) {
283292
if (e.getCode() == HttpURLConnection.HTTP_NOT_FOUND) {

claimManagement/src/main/java/org/openimis/imisclaims/SynchronizeService.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ public class SynchronizeService extends JobIntentService {
5656

5757
private static final String claimResponseLine = "[%s] %s";
5858

59-
private Global global;
60-
private SQLHandler sqlHandler;
61-
private StorageManager storageManager;
59+
protected Global global;
60+
protected SQLHandler sqlHandler;
61+
protected StorageManager storageManager;
62+
protected PostNewClaims postNewClaims;
6263

6364
@Override
6465
public void onCreate() {
@@ -68,6 +69,10 @@ public void onCreate() {
6869
storageManager = StorageManager.of(this);
6970
}
7071

72+
public void setPostNewClaims(PostNewClaims postNewClaims) {
73+
this.postNewClaims = postNewClaims;
74+
}
75+
7176
public static void uploadClaims(Context context) {
7277
Intent intent = new Intent();
7378
intent.setAction(ACTION_UPLOAD_CLAIMS);
@@ -98,7 +103,7 @@ protected void onHandleWork(@NonNull Intent intent) {
98103
}
99104
}
100105

101-
private void handleUploadClaims() {
106+
protected void handleUploadClaims() {
102107
if (!global.isNetworkAvailable()) {
103108
broadcastError(getResources().getString(R.string.CheckInternet), ACTION_UPLOAD_CLAIMS);
104109
return;
@@ -111,7 +116,10 @@ private void handleUploadClaims() {
111116
}
112117

113118
try {
114-
List<PostNewClaims.Result> results = new PostNewClaims().execute(PendingClaim.fromJson(claims));
119+
if (postNewClaims == null) {
120+
postNewClaims = new PostNewClaims();
121+
}
122+
List<PostNewClaims.Result> results = postNewClaims.execute(PendingClaim.fromJson(claims));
115123
JSONArray claimStatus = processClaimResponse(results);
116124
broadcastSyncSuccess(claimStatus);
117125
} catch (Exception e) {
@@ -121,7 +129,7 @@ private void handleUploadClaims() {
121129
}
122130
}
123131

124-
private JSONArray processClaimResponse(List<PostNewClaims.Result> results) {
132+
protected JSONArray processClaimResponse(List<PostNewClaims.Result> results) {
125133
JSONArray jsonResults = new JSONArray();
126134
String date = AppInformation.DateTimeInfo.getDefaultIsoDatetimeFormatter().format(new Date());
127135
for (PostNewClaims.Result result : results) {
@@ -257,7 +265,7 @@ private Uri createClaimExportZip(ArrayList<File> exportedClaims) {
257265
zipFile);
258266
}
259267

260-
private void handleGetClaimCount() {
268+
protected void handleGetClaimCount() {
261269
JSONObject counts = sqlHandler.getClaimCounts();
262270

263271
int enteredCount = counts.optInt(SQLHandler.CLAIM_UPLOAD_STATUS_ENTERED, 0);

0 commit comments

Comments
 (0)