Skip to content
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

Hilary 2022 03 14 #470

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions opensrp-chw-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ dependencies {
exclude group: 'com.android.support', module: 'design'
exclude group: 'io.ona.rdt-capture', module: 'lib'
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'com.github.raihan-mpower', module: 'FancyAlertDialog-Android'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this might affect the app APK build or cause runtime exceptions.
Is this animation part of the test?

}

compileOnly 'com.ibm.fhir:fhir-model:4.7.0'
Expand Down
6 changes: 6 additions & 0 deletions opensrp-chw-core/src/main/res/anim/slide_in.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this animation part of the test?

<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0"/>
6 changes: 6 additions & 0 deletions opensrp-chw-core/src/main/res/anim/slide_out.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<translate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this animation part of the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, but the library was not building without those.

xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="0"
android:toXDelta="100%p"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.smartregister.chw.core.repository;

import static org.smartregister.repository.BaseRepository.COLLATE_NOCASE;

import net.sqlcipher.MatrixCursor;
import net.sqlcipher.database.SQLiteDatabase;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.smartregister.chw.anc.util.Constants;
import org.smartregister.chw.core.BaseRobolectricTest;

import java.util.HashMap;

public class MalariaRegisterRepositoryTest extends BaseRobolectricTest {
@Mock
private MalariaRegisterRepository malariaRegisterRepository;

@Mock
private SQLiteDatabase database;

@Captor
ArgumentCaptor<String> tableNameCaptor;
@Captor
ArgumentCaptor<String[]> tableColumnsCaptor;
@Captor
ArgumentCaptor<String> selectionCaptor;
@Captor
ArgumentCaptor<String[]> selectionArgsCaptor;
@Captor
ArgumentCaptor<String> groupByCaptor;
@Captor
ArgumentCaptor<String> havingCaptor;
@Captor
ArgumentCaptor<String> orderByCaptor;


@Before
public void setUp() throws Exception {
malariaRegisterRepository = Mockito.spy(new MalariaRegisterRepository());
Mockito.doReturn(database).when(malariaRegisterRepository).getReadableDatabase();
}

@Test
public void testDatabaseQueryIsCreatedWithTheCorrectArgumentInGetFamilyNamePhone(){
String baseEntityId = "4b3e6408-0549-470a-b24a-82ac71180a30";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this test covers the following lines https://github.com/opensrp/opensrp-client-chw-core/blob/master/opensrp-chw-core/src/main/java/org/smartregister/chw/core/repository/MalariaRegisterRepository.java#L42-L51, add an assertion for this also since this will not longer be covered having been already marked as code covered by tests but not actually tested

String selection = "base_entity_id = ? "+COLLATE_NOCASE;
malariaRegisterRepository.getFamilyNameAndPhone(baseEntityId);
Mockito.verify(database).query(tableNameCaptor.capture(), tableColumnsCaptor.capture(), selectionCaptor.capture(), selectionArgsCaptor.capture(),
groupByCaptor.capture(), havingCaptor.capture(), orderByCaptor.capture());
Assert.assertEquals(MalariaRegisterRepository.TABLE_NAME, tableNameCaptor.getValue());
Assert.assertArrayEquals(MalariaRegisterRepository.TABLE_COLUMNS, tableColumnsCaptor.getValue());
Assert.assertArrayEquals(new String[]{baseEntityId}, selectionArgsCaptor.getValue());
Assert.assertEquals(selection, selectionCaptor.getValue());
}



@Test
public void testGetFamilyNameAndPhoneWithBaseEntityIdReturnsCorrectDetails(){

String correctBaseEntityId = "4b3e6408-0549-470a-b24a-82ac71180a30";

HashMap<String, String> results = new HashMap<>();
results.put(Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_NAME, "Emilio Mwai Kibaki");
results.put(Constants.ANC_MEMBER_OBJECTS.FAMILY_HEAD_PHONE, "0799938383");

MatrixCursor mockCursor = new MatrixCursor(new String[]
{
MalariaRegisterRepository.FIRST_NAME,
MalariaRegisterRepository.LAST_NAME,
MalariaRegisterRepository.MIDDLE_NAME,
MalariaRegisterRepository.PHONE_NUMBER
});

mockCursor.newRow()
.add("Emilio")
.add("Kibaki")
.add("Mwai")
.add("0799938383");

Mockito.doReturn(mockCursor).when(database).query(Mockito.any(), Mockito.any(), Mockito.any(),
Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());

Assert.assertEquals(results, malariaRegisterRepository.getFamilyNameAndPhone(correctBaseEntityId));

}

}