-
Notifications
You must be signed in to change notification settings - Fork 18
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
base: master
Are you sure you want to change the base?
Hilary 2022 03 14 #470
Changes from all commits
d5742af
ead4f11
2cd689e
ca4f3e5
4e72ffc
dcf6824
fe96f67
4c823a3
6e5800a
599dbed
e9719c7
0aab92e
358aaad
32bf229
ad00a73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<translate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this animation part of the test? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
||
} | ||
|
||
} |
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.
It seems that this might affect the app APK build or cause runtime exceptions.
Is this animation part of the test?