Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza-vd committed May 20, 2022
1 parent 336a970 commit 9390d36
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ protected ArrayList<String> doInBackground(Void... params) {
String motherBaseEntityId = Utils.getValue(childDetails.getColumnmaps(), Constants.KEY.RELATIONAL_ID, false);
if (!TextUtils.isEmpty(motherBaseEntityId) && !TextUtils.isEmpty(baseEntityId)) {

String whereClause = " WHERE " + Utils.metadata().getRegisterQueryProvider().getChildDetailsTable() + ".relational_id IN ('" + motherBaseEntityId + "') AND " +
Utils.metadata().getRegisterQueryProvider().getDemographicTable() + ".date_removed IS NULL AND " +
Utils.metadata().getRegisterQueryProvider().getDemographicTable() + ".dod IS NULL AND " +
Utils.metadata().getRegisterQueryProvider().getDemographicTable() + ".is_closed = 0";
String whereClause = constructWhereClause(motherBaseEntityId);
List<HashMap<String, String>> childList = ChildLibrary.getInstance()
.eventClientRepository()
.rawQuery(ChildLibrary.getInstance().getRepository().getReadableDatabase(),
Utils.metadata().getRegisterQueryProvider().mainRegisterQuery() + whereClause );
Utils.metadata().getRegisterQueryProvider().mainRegisterQuery() + whereClause);


List<CommonPersonObject> children = new ArrayList<>();
Expand All @@ -67,6 +64,13 @@ protected ArrayList<String> doInBackground(Void... params) {
return null;
}

private String constructWhereClause(String motherBaseEntityId) {
return " WHERE " + Utils.metadata().getRegisterQueryProvider().getChildDetailsTable() + ".relational_id IN ('" + motherBaseEntityId + "') AND " +
Utils.metadata().getRegisterQueryProvider().getDemographicTable() + ".date_removed IS NULL AND " +
Utils.metadata().getRegisterQueryProvider().getDemographicTable() + ".dod IS NULL AND " +
Utils.metadata().getRegisterQueryProvider().getDemographicTable() + ".is_closed = 0";
}

@Override
protected void onPostExecute(ArrayList<String> baseEntityIds) {
super.onPostExecute(baseEntityIds);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.smartregister.child.task;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.child.BaseUnitTest;
import org.smartregister.child.contract.IGetSiblings;
import org.smartregister.child.util.Constants;
import org.smartregister.child.util.DBConstants;
import org.smartregister.commonregistry.CommonPersonObjectClient;
import org.smartregister.utils.Assert;

import java.util.HashMap;

public class GetSiblingsTaskTest extends BaseUnitTest {

private GetSiblingsTask getSiblingsTask;
private CommonPersonObjectClient commonPersonObjectClient;

@Mock
private IGetSiblings getSiblings;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);

HashMap<String, String> details = new HashMap<>();
details.put(DBConstants.KEY.ZEIR_ID, "123123");
commonPersonObjectClient = new CommonPersonObjectClient("baseEntityId", details, Constants.KEY.CHILD);
getSiblingsTask = new GetSiblingsTask(commonPersonObjectClient, getSiblings);
}

@Test
public void testConstructorNotNull() {
Assert.notNull(getSiblingsTask);
}

@Test
public void testConstructWhereClauseFiltersDeadChild() {
String whereClause = ReflectionHelpers.callInstanceMethod(getSiblingsTask, "constructWhereClause", ReflectionHelpers.ClassParameter.from(String.class, "123"));
assertEquals(" WHERE ec_child_details.relational_id IN ('123') AND ec_client.date_removed IS NULL AND ec_client.dod IS NULL AND ec_client.is_closed = 0", whereClause);
}

}

0 comments on commit 9390d36

Please sign in to comment.