From c811fda17184c9fa64f08a57651424a8290b3ea3 Mon Sep 17 00:00:00 2001 From: Denis Rwelamila Date: Fri, 13 Sep 2019 11:02:48 +0300 Subject: [PATCH 01/19] add anc buttons --- .../src/main/res/drawable/border.xml | 8 +++ .../main/res/layout/view_record_malaria.xml | 53 ++++++++++--------- 2 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 opensrp-chw-malaria/src/main/res/drawable/border.xml diff --git a/opensrp-chw-malaria/src/main/res/drawable/border.xml b/opensrp-chw-malaria/src/main/res/drawable/border.xml new file mode 100644 index 0000000..b70eee0 --- /dev/null +++ b/opensrp-chw-malaria/src/main/res/drawable/border.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml b/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml index deb8f71..bd428b3 100644 --- a/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml +++ b/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml @@ -1,35 +1,36 @@ + android:id="@+id/record_malaria" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/white" + android:orientation="vertical" + android:paddingTop="10dp"> + + android:textColor="@color/white" /> + android:textColor="@color/grey" + android:visibility="visible" /> + android:id="@+id/view_record" + android:layout_width="match_parent" + android:layout_height="1px" + android:layout_marginTop="5dp" + android:background="@color/light_grey" /> \ No newline at end of file From d5b1f198a8343ff11566dc2afbdebdd6333569a7 Mon Sep 17 00:00:00 2001 From: Denis Rwelamila Date: Fri, 13 Sep 2019 12:53:51 +0300 Subject: [PATCH 02/19] version_name --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 09f0f70..48d5da8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=5.0.20-SNAPSHOT +VERSION_NAME=1.0.12-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client CHW Malaria Library From 8b4b39adbc48fe3d968b712fb95fff7a9c34f7c4 Mon Sep 17 00:00:00 2001 From: Denis Rwelamila Date: Fri, 20 Sep 2019 12:31:55 +0300 Subject: [PATCH 03/19] add undo visit --- .../activity/BaseMalariaProfileActivity.java | 10 +++++ .../main/res/layout/view_record_malaria.xml | 43 +++++++++++++++++++ .../src/main/res/values/strings.xml | 2 + 3 files changed, 55 insertions(+) diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java index b0e61e1..b169ea9 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java @@ -28,6 +28,7 @@ import org.smartregister.chw.malaria.presenter.BaseMalariaProfilePresenter; import org.smartregister.chw.malaria.util.Constants; import org.smartregister.chw.malaria.util.Util; +import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.AlertStatus; import org.smartregister.malaria.R; import org.smartregister.view.activity.BaseProfileActivity; @@ -41,6 +42,7 @@ public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View, MalariaProfileContract.InteractorCallBack { protected MemberObject MEMBER_OBJECT; protected MalariaProfileContract.Presenter profilePresenter; + protected CommonPersonObjectClient client; protected TextView textViewName; protected TextView textViewGender; protected TextView textViewLocation; @@ -54,6 +56,8 @@ public class BaseMalariaProfileActivity extends BaseProfileActivity implements M protected RelativeLayout rlLastVisit; protected RelativeLayout rlUpcomingServices; protected RelativeLayout rlFamilyServicesDue; + protected RelativeLayout visitStatus; + protected TextView textViewUndo; private TextView tvUpComingServices; private TextView tvFamilyStatus; private SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM", Locale.getDefault()); @@ -106,6 +110,8 @@ protected void onCreation() { progressBar = findViewById(R.id.progress_bar); + visitStatus = findViewById(R.id.record_visit_status_bar); + findViewById(R.id.rlLastVisit).setOnClickListener(this); findViewById(R.id.rlUpcomingServices).setOnClickListener(this); findViewById(R.id.rlFamilyServicesDue).setOnClickListener(this); @@ -119,7 +125,11 @@ protected void onCreation() { textViewAncVisitNotDone = findViewById(R.id.textview_anc_visit_not_done); textViewAncVisitNotDone.setOnClickListener(this); + textViewUndo = findViewById(R.id.textview_undo); + textViewUndo.setOnClickListener(this); + MEMBER_OBJECT = (MemberObject) getIntent().getSerializableExtra(Constants.MALARIA_MEMBER_OBJECT.MEMBER_OBJECT); + client = (CommonPersonObjectClient) getIntent().getSerializableExtra("CLIENT"); initializePresenter(); diff --git a/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml b/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml index bd428b3..564df4c 100644 --- a/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml +++ b/opensrp-chw-malaria/src/main/res/layout/view_record_malaria.xml @@ -50,6 +50,49 @@ android:textColor="@color/grey" android:visibility="visible" /> + + + + + + + + + + + + + Call Record ANC visit ANC visit not done + Not visiting this month + UNDO From a342dec3982f0f5c6c06525476cddb8b7fa813ec Mon Sep 17 00:00:00 2001 From: Denis Rwelamila Date: Fri, 20 Sep 2019 13:44:39 +0300 Subject: [PATCH 04/19] domain testing --- .../domain/MemberObjectTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java index 1570bdb..be5aec3 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java @@ -19,6 +19,7 @@ public void getFirstName() { Assert.assertEquals("Denis", memberObject.getFirstName()); } + @Test public void getMiddleName() { memberObject.setMiddleName("Talemwa"); @@ -54,5 +55,23 @@ public void testIsClosed() { memberObject.setIsClosed(false); Assert.assertFalse(memberObject.getIsClosed()); } + + @Test + public void getUniqueId() { + memberObject.setUniqueId("#1223"); + Assert.assertEquals("#1223", memberObject.getUniqueId()); + } + + @Test + public void getRelationalid() { + memberObject.setRelationalId("#1223"); + Assert.assertEquals("#1223", memberObject.getRelationalid()); + } + + @Test + public void getDetails() { + memberObject.setDetails("#1223"); + Assert.assertEquals("#1223", memberObject.getDetails()); + } } From f870a0974b99cb6f4df2730f7597f8ae7e5a96af Mon Sep 17 00:00:00 2001 From: Denis Rwelamila Date: Fri, 20 Sep 2019 14:00:25 +0300 Subject: [PATCH 05/19] fix relationid error --- .../test/java/org/smartregister/domain/MemberObjectTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java index be5aec3..6f1ee78 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java @@ -64,7 +64,7 @@ public void getUniqueId() { @Test public void getRelationalid() { - memberObject.setRelationalId("#1223"); + memberObject.setRelationalid("#1223"); Assert.assertEquals("#1223", memberObject.getRelationalid()); } From c768f4678c61ec958eb8b45191040ddf4be37867 Mon Sep 17 00:00:00 2001 From: Denis Rwelamila Date: Fri, 20 Sep 2019 14:00:25 +0300 Subject: [PATCH 06/19] show profile image if exists --- .../chw/malaria/activity/BaseMalariaProfileActivity.java | 7 +++++++ .../java/org/smartregister/domain/MemberObjectTest.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java index b169ea9..c669a05 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/activity/BaseMalariaProfileActivity.java @@ -30,6 +30,7 @@ import org.smartregister.chw.malaria.util.Util; import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.AlertStatus; +import org.smartregister.helper.ImageRenderHelper; import org.smartregister.malaria.R; import org.smartregister.view.activity.BaseProfileActivity; @@ -38,11 +39,14 @@ import java.util.Date; import java.util.Locale; +import de.hdodenhof.circleimageview.CircleImageView; + public class BaseMalariaProfileActivity extends BaseProfileActivity implements MalariaProfileContract.View, MalariaProfileContract.InteractorCallBack { protected MemberObject MEMBER_OBJECT; protected MalariaProfileContract.Presenter profilePresenter; protected CommonPersonObjectClient client; + protected CircleImageView imageView; protected TextView textViewName; protected TextView textViewGender; protected TextView textViewLocation; @@ -128,6 +132,9 @@ protected void onCreation() { textViewUndo = findViewById(R.id.textview_undo); textViewUndo.setOnClickListener(this); + imageView = findViewById(R.id.imageview_profile); + imageRenderHelper = new ImageRenderHelper(this); + MEMBER_OBJECT = (MemberObject) getIntent().getSerializableExtra(Constants.MALARIA_MEMBER_OBJECT.MEMBER_OBJECT); client = (CommonPersonObjectClient) getIntent().getSerializableExtra("CLIENT"); diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java index be5aec3..6f1ee78 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java @@ -64,7 +64,7 @@ public void getUniqueId() { @Test public void getRelationalid() { - memberObject.setRelationalId("#1223"); + memberObject.setRelationalid("#1223"); Assert.assertEquals("#1223", memberObject.getRelationalid()); } From c8059b85a15d0926a38508f8db55b63fd4a98289 Mon Sep 17 00:00:00 2001 From: Denis Rwelamila Date: Mon, 23 Sep 2019 12:24:11 +0300 Subject: [PATCH 07/19] test test date --- .../java/org/smartregister/domain/MemberObjectTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java index 6f1ee78..643e714 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java @@ -73,5 +73,12 @@ public void getDetails() { memberObject.setDetails("#1223"); Assert.assertEquals("#1223", memberObject.getDetails()); } + + @Test + public void getDateChwMalariaTest() { + memberObject.setDateChwMalariaTest("#1223"); + Assert.assertEquals("#1223", memberObject.getDateChwMalariaTest()); + } + } From ea0bd3d128cba2f7799b0613c7529ebc82004a68 Mon Sep 17 00:00:00 2001 From: Denis R Date: Thu, 3 Oct 2019 12:54:43 +0300 Subject: [PATCH 08/19] trigger codacy From 9f914c0b242270b78a1a0ae2e566ef7231f013e9 Mon Sep 17 00:00:00 2001 From: Denis R Date: Wed, 9 Oct 2019 09:23:54 +0300 Subject: [PATCH 09/19] loose additional setters --- .../domain/MemberObjectTest.java | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java index 643e714..df52429 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java @@ -56,29 +56,5 @@ public void testIsClosed() { Assert.assertFalse(memberObject.getIsClosed()); } - @Test - public void getUniqueId() { - memberObject.setUniqueId("#1223"); - Assert.assertEquals("#1223", memberObject.getUniqueId()); - } - - @Test - public void getRelationalid() { - memberObject.setRelationalid("#1223"); - Assert.assertEquals("#1223", memberObject.getRelationalid()); - } - - @Test - public void getDetails() { - memberObject.setDetails("#1223"); - Assert.assertEquals("#1223", memberObject.getDetails()); - } - - @Test - public void getDateChwMalariaTest() { - memberObject.setDateChwMalariaTest("#1223"); - Assert.assertEquals("#1223", memberObject.getDateChwMalariaTest()); - } - } From 37ead708e8d14f6b50da339369597a03c15498d5 Mon Sep 17 00:00:00 2001 From: Denis R Date: Wed, 9 Oct 2019 11:14:26 +0300 Subject: [PATCH 10/19] test malaria register fragment --- ...BaseMalariaRegisterFragmentPresenterTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java index ca8d307..1cd9076 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java @@ -7,12 +7,17 @@ import org.mockito.MockitoAnnotations; import org.smartregister.chw.malaria.contract.MalariaRegisterFragmentContract; import org.smartregister.chw.malaria.presenter.BaseMalariaRegisterFragmentPresenter; +import org.smartregister.chw.malaria.util.Constants; +import org.smartregister.chw.malaria.util.DBConstants; public class BaseMalariaRegisterFragmentPresenterTest { @Mock protected MalariaRegisterFragmentContract.View view; + + @Mock protected MalariaRegisterFragmentContract.Model model; + private BaseMalariaRegisterFragmentPresenter baseMalariaRegisterFragmentPresenter; @Before @@ -32,4 +37,15 @@ public void testGetMainCondition() { Assert.assertEquals("", baseMalariaRegisterFragmentPresenter.getMainCondition()); } + @Test + public void getDueFilterCondition() { + Assert.assertEquals(" (cast( julianday(STRFTIME('%Y-%m-%d', datetime('now'))) - julianday(IFNULL(SUBSTR(malaria_test_date,7,4)|| '-' || SUBSTR(malaria_test_date,4,2) || '-' || SUBSTR(malaria_test_date,1,2),'')) as integer) between 7 and 14) ", baseMalariaRegisterFragmentPresenter.getDueFilterCondition()); + } + + @Test + public void getDefaultSortQuery() { + Assert.assertEquals(Constants.TABLES.MALARIA_CONFIRMATION + "." + DBConstants.KEY.LAST_INTERACTED_WITH + " DESC ", baseMalariaRegisterFragmentPresenter.getDefaultSortQuery()); + } + + } \ No newline at end of file From 8e750e16cb050b44d20ddb1fa9e989741fb50160 Mon Sep 17 00:00:00 2001 From: Denis R Date: Wed, 9 Oct 2019 11:36:39 +0300 Subject: [PATCH 11/19] clean ups --- .../BaseMalariaProfileActivityTest.java | 24 +------- .../domain/MemberObjectTest.java | 60 ------------------- 2 files changed, 3 insertions(+), 81 deletions(-) delete mode 100644 opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java index 8fff95e..94c0ad5 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java @@ -1,26 +1,20 @@ package org.smartregister.activity; -import android.graphics.Color; -import android.view.View; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.Spy; import org.smartregister.chw.malaria.activity.BaseMalariaProfileActivity; +import org.smartregister.chw.malaria.presenter.BaseMalariaProfilePresenter; public class BaseMalariaProfileActivityTest { @Mock protected BaseMalariaProfileActivity baseMalariaProfileActivity; - @Spy - protected BaseMalariaProfileActivity spy; - @Mock - protected View view; + protected BaseMalariaProfilePresenter presenter; @Before public void setUp() { @@ -35,18 +29,6 @@ public void assertNotNull() { @Test public void setProfileViewWithData() { baseMalariaProfileActivity.setProfileViewWithData(); - Mockito.verify(view, Mockito.never()).setVisibility(View.VISIBLE); - } - - @Test - public void setDueColor() { - baseMalariaProfileActivity.setDueColor(); - Mockito.verify(view, Mockito.never()).setBackgroundColor(Color.BLUE); - } - - @Test - public void setOverDueColor() { - baseMalariaProfileActivity.setOverDueColor(); - Mockito.verify(view, Mockito.never()).setBackgroundColor(Color.RED); + Mockito.verify(presenter).recordMalariaButton(12); } } diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java deleted file mode 100644 index df52429..0000000 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.smartregister.domain; - -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.smartregister.chw.malaria.domain.MemberObject; -import org.smartregister.commonregistry.CommonPersonObjectClient; - -public class MemberObjectTest { - @Mock - private CommonPersonObjectClient client = Mockito.mock(CommonPersonObjectClient.class); - - private MemberObject memberObject = new MemberObject(client); - - @Test - public void getFirstName() { - memberObject.setFirstName("Denis"); - Assert.assertEquals("Denis", memberObject.getFirstName()); - } - - - @Test - public void getMiddleName() { - memberObject.setMiddleName("Talemwa"); - Assert.assertEquals("Talemwa", memberObject.getMiddleName()); - } - - @Test - public void getLastName() { - memberObject.setLastName("Rwelamila"); - Assert.assertEquals("Rwelamila", memberObject.getLastName()); - } - - @Test - public void getAddress() { - memberObject.setAddress("123 Rd"); - Assert.assertEquals("123 Rd", memberObject.getAddress()); - } - - @Test - public void getGender() { - memberObject.setGender("Male"); - Assert.assertEquals("Male", memberObject.getGender()); - } - - @Test - public void getAge() { - memberObject.setAge("123"); - Assert.assertEquals("123", memberObject.getAge()); - } - - @Test - public void testIsClosed() { - memberObject.setIsClosed(false); - Assert.assertFalse(memberObject.getIsClosed()); - } - -} - From 7681cd74e7a098c5143e0f6448ab34db81feb6d1 Mon Sep 17 00:00:00 2001 From: Denis R Date: Wed, 9 Oct 2019 11:36:39 +0300 Subject: [PATCH 12/19] clean ups --- .../BaseMalariaProfileActivityTest.java | 28 --------- .../domain/MemberObjectTest.java | 60 ------------------- 2 files changed, 88 deletions(-) delete mode 100644 opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java index 8fff95e..45e5938 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/activity/BaseMalariaProfileActivityTest.java @@ -1,27 +1,16 @@ package org.smartregister.activity; -import android.graphics.Color; -import android.view.View; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.Spy; import org.smartregister.chw.malaria.activity.BaseMalariaProfileActivity; public class BaseMalariaProfileActivityTest { @Mock protected BaseMalariaProfileActivity baseMalariaProfileActivity; - @Spy - protected BaseMalariaProfileActivity spy; - - @Mock - protected View view; - @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -32,21 +21,4 @@ public void assertNotNull() { Assert.assertNotNull(baseMalariaProfileActivity); } - @Test - public void setProfileViewWithData() { - baseMalariaProfileActivity.setProfileViewWithData(); - Mockito.verify(view, Mockito.never()).setVisibility(View.VISIBLE); - } - - @Test - public void setDueColor() { - baseMalariaProfileActivity.setDueColor(); - Mockito.verify(view, Mockito.never()).setBackgroundColor(Color.BLUE); - } - - @Test - public void setOverDueColor() { - baseMalariaProfileActivity.setOverDueColor(); - Mockito.verify(view, Mockito.never()).setBackgroundColor(Color.RED); - } } diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java deleted file mode 100644 index df52429..0000000 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/domain/MemberObjectTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.smartregister.domain; - -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.smartregister.chw.malaria.domain.MemberObject; -import org.smartregister.commonregistry.CommonPersonObjectClient; - -public class MemberObjectTest { - @Mock - private CommonPersonObjectClient client = Mockito.mock(CommonPersonObjectClient.class); - - private MemberObject memberObject = new MemberObject(client); - - @Test - public void getFirstName() { - memberObject.setFirstName("Denis"); - Assert.assertEquals("Denis", memberObject.getFirstName()); - } - - - @Test - public void getMiddleName() { - memberObject.setMiddleName("Talemwa"); - Assert.assertEquals("Talemwa", memberObject.getMiddleName()); - } - - @Test - public void getLastName() { - memberObject.setLastName("Rwelamila"); - Assert.assertEquals("Rwelamila", memberObject.getLastName()); - } - - @Test - public void getAddress() { - memberObject.setAddress("123 Rd"); - Assert.assertEquals("123 Rd", memberObject.getAddress()); - } - - @Test - public void getGender() { - memberObject.setGender("Male"); - Assert.assertEquals("Male", memberObject.getGender()); - } - - @Test - public void getAge() { - memberObject.setAge("123"); - Assert.assertEquals("123", memberObject.getAge()); - } - - @Test - public void testIsClosed() { - memberObject.setIsClosed(false); - Assert.assertFalse(memberObject.getIsClosed()); - } - -} - From 66b88c83fb2de3782bee678e908a468ec0986f13 Mon Sep 17 00:00:00 2001 From: Denis R Date: Wed, 9 Oct 2019 16:09:50 +0300 Subject: [PATCH 13/19] test BaseMalariaRegisterFragmentPresenter --- .../presenter/BaseMalariaProfilePresenterTest.java | 8 +++++++- .../BaseMalariaRegisterFragmentPresenterTest.java | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java index 9f69578..ef35381 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaProfilePresenterTest.java @@ -56,4 +56,10 @@ public void malariaTestDatePeriodGreaterThanTen() { profilePresenter.recordMalariaButton(14); verify(view).setOverDueColor(); } -} + + @Test + public void refreshProfileBottom() { + profilePresenter.refreshProfileBottom(); + verify(interactor).refreshProfileInfo(memberObject, profilePresenter.getView()); + } + } diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java index 1cd9076..c8a3297 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterFragmentPresenterTest.java @@ -33,7 +33,7 @@ public void assertNotNull() { } @Test - public void testGetMainCondition() { + public void getMainCondition() { Assert.assertEquals("", baseMalariaRegisterFragmentPresenter.getMainCondition()); } @@ -47,5 +47,11 @@ public void getDefaultSortQuery() { Assert.assertEquals(Constants.TABLES.MALARIA_CONFIRMATION + "." + DBConstants.KEY.LAST_INTERACTED_WITH + " DESC ", baseMalariaRegisterFragmentPresenter.getDefaultSortQuery()); } + @Test + public void getMainTable() { + Assert.assertEquals(Constants.TABLES.MALARIA_CONFIRMATION, baseMalariaRegisterFragmentPresenter.getMainTable()); + } + + } \ No newline at end of file From ee37882febad24c268400923c66a3f300765b3c6 Mon Sep 17 00:00:00 2001 From: Denis R Date: Thu, 10 Oct 2019 10:30:10 +0300 Subject: [PATCH 14/19] test BaseMalariaRegisterPresenter --- .../BaseMalariaProfilePresenter.java | 3 +- .../BaseMalariaRegisterPresenter.java | 2 +- .../BaseMalariaRegisterPresenterTest.java | 31 +++++++++++++------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java index 137b69c..d8a4cd0 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java @@ -32,8 +32,9 @@ public void fillProfileData(MemberObject memberObject) { @Override public void recordMalariaButton(int days_from_malaria_test_date) { - if (getView() == null) + if (getView() == null) { return; + } if (days_from_malaria_test_date < 7 || days_from_malaria_test_date > 14) { getView().hideView(); diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java index 6c96b4f..d7dd691 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java @@ -16,7 +16,7 @@ public class BaseMalariaRegisterPresenter implements MalariaRegisterContract.Pre public static final String TAG = BaseMalariaRegisterPresenter.class.getName(); protected WeakReference viewReference; - protected MalariaRegisterContract.Interactor interactor; + private MalariaRegisterContract.Interactor interactor; protected MalariaRegisterContract.Model model; public BaseMalariaRegisterPresenter(MalariaRegisterContract.View view, MalariaRegisterContract.Model model, MalariaRegisterContract.Interactor interactor) { diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java index ae75645..8e2084a 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java @@ -1,24 +1,24 @@ package org.smartregister.presenter; import org.json.JSONObject; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.smartregister.chw.malaria.contract.MalariaRegisterContract; +import org.powermock.reflect.Whitebox; import org.smartregister.chw.malaria.presenter.BaseMalariaRegisterPresenter; - +import org.smartregister.view.contract.BaseRegisterContract; @PrepareForTest(BaseMalariaRegisterPresenter.class) public class BaseMalariaRegisterPresenterTest { @Mock protected BaseMalariaRegisterPresenter baseMalariaRegisterPresenter; - @Mock - protected MalariaRegisterContract.View view; + protected BaseRegisterContract.View baseView; @Before public void setUp() { @@ -26,21 +26,32 @@ public void setUp() { } @Test - public void startForm() throws Exception { + public void startFormWhenEntityIdIsNull() throws Exception { baseMalariaRegisterPresenter.startForm("formName", "", "121212121212", "231231231231"); - Mockito.verify(view, Mockito.never()).startFormActivity(null); + Mockito.verify(baseView, Mockito.never()).startFormActivity(null); + } + + @Test + public void startFormWhenEntityIdIsNotNull() throws Exception { + baseMalariaRegisterPresenter.startForm("formName", "12131212", "121212121212", "231231231231"); + PowerMockito.verifyPrivate(baseMalariaRegisterPresenter).invoke("getView"); } @Test public void startFormWithEntityId() throws Exception { baseMalariaRegisterPresenter.startForm("formName", "12121212", "121212121212", "231231231231"); - Mockito.verify(view, Mockito.never()).startFormActivity(new JSONObject()); + Mockito.verify(baseView, Mockito.never()).startFormActivity(new JSONObject()); } +// @Test +// public void saveForm() { +// baseMalariaRegisterPresenter.saveForm("{}"); +// Mockito.verify(baseView).showProgressDialog(1); +// } + @Test - public void saveForm() { - baseMalariaRegisterPresenter.saveForm("{}"); - Mockito.verify(view, Mockito.never()).showProgressDialog(1); + public void getViewWhenViewIsNull() throws Exception { + Assert.assertNull(Whitebox.invokeMethod(baseMalariaRegisterPresenter, "getView")); } } From de067dbecdd7be5cbc0c88edffa830991196afc7 Mon Sep 17 00:00:00 2001 From: Denis R Date: Thu, 10 Oct 2019 10:30:10 +0300 Subject: [PATCH 15/19] test BaseMalariaRegisterPresenter --- .../BaseMalariaProfilePresenter.java | 3 +- .../BaseMalariaRegisterPresenter.java | 2 +- .../BaseMalariaRegisterPresenterTest.java | 32 +++++++++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java index 137b69c..d8a4cd0 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaProfilePresenter.java @@ -32,8 +32,9 @@ public void fillProfileData(MemberObject memberObject) { @Override public void recordMalariaButton(int days_from_malaria_test_date) { - if (getView() == null) + if (getView() == null) { return; + } if (days_from_malaria_test_date < 7 || days_from_malaria_test_date > 14) { getView().hideView(); diff --git a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java index 6c96b4f..d7dd691 100644 --- a/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java +++ b/opensrp-chw-malaria/src/main/java/org/smartregister/chw/malaria/presenter/BaseMalariaRegisterPresenter.java @@ -16,7 +16,7 @@ public class BaseMalariaRegisterPresenter implements MalariaRegisterContract.Pre public static final String TAG = BaseMalariaRegisterPresenter.class.getName(); protected WeakReference viewReference; - protected MalariaRegisterContract.Interactor interactor; + private MalariaRegisterContract.Interactor interactor; protected MalariaRegisterContract.Model model; public BaseMalariaRegisterPresenter(MalariaRegisterContract.View view, MalariaRegisterContract.Model model, MalariaRegisterContract.Interactor interactor) { diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java index ae75645..566bfb3 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java @@ -1,24 +1,25 @@ package org.smartregister.presenter; import org.json.JSONObject; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.smartregister.chw.malaria.contract.MalariaRegisterContract; +import org.powermock.reflect.Whitebox; import org.smartregister.chw.malaria.presenter.BaseMalariaRegisterPresenter; - +import org.smartregister.view.contract.BaseRegisterContract; @PrepareForTest(BaseMalariaRegisterPresenter.class) public class BaseMalariaRegisterPresenterTest { @Mock protected BaseMalariaRegisterPresenter baseMalariaRegisterPresenter; - @Mock - protected MalariaRegisterContract.View view; + protected BaseRegisterContract.View baseView; @Before public void setUp() { @@ -26,21 +27,32 @@ public void setUp() { } @Test - public void startForm() throws Exception { + public void startFormWhenEntityIdIsNull() throws Exception { baseMalariaRegisterPresenter.startForm("formName", "", "121212121212", "231231231231"); - Mockito.verify(view, Mockito.never()).startFormActivity(null); + Mockito.verify(baseView, Mockito.never()).startFormActivity(null); + } + + @Test + public void startFormWhenEntityIdIsNotNull() throws Exception { + baseMalariaRegisterPresenter.startForm("formName", "12131212", "121212121212", "231231231231"); + PowerMockito.verifyPrivate(baseMalariaRegisterPresenter).invoke("getView"); } @Test public void startFormWithEntityId() throws Exception { baseMalariaRegisterPresenter.startForm("formName", "12121212", "121212121212", "231231231231"); - Mockito.verify(view, Mockito.never()).startFormActivity(new JSONObject()); + Mockito.verify(baseView, Mockito.never()).startFormActivity(new JSONObject()); } +// @Test +// public void saveForm() { +// baseMalariaRegisterPresenter.saveForm("{}"); +// Mockito.verify(baseView).showProgressDialog(1); +// } + @Test - public void saveForm() { - baseMalariaRegisterPresenter.saveForm("{}"); - Mockito.verify(view, Mockito.never()).showProgressDialog(1); + public void getViewWhenViewIsNull() throws Exception { + Assert.assertNull(Whitebox.invokeMethod(baseMalariaRegisterPresenter, "getView")); } } From 84fa909e14bfbf2eed04bce4cd89933226d3f146 Mon Sep 17 00:00:00 2001 From: Denis R Date: Thu, 10 Oct 2019 10:46:47 +0300 Subject: [PATCH 16/19] fix build --- .../BaseMalariaRegisterPresenterTest.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java index 566bfb3..0770917 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java @@ -7,11 +7,10 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.reflect.Whitebox; +import org.smartregister.chw.malaria.contract.MalariaRegisterContract; import org.smartregister.chw.malaria.presenter.BaseMalariaRegisterPresenter; -import org.smartregister.view.contract.BaseRegisterContract; @PrepareForTest(BaseMalariaRegisterPresenter.class) public class BaseMalariaRegisterPresenterTest { @@ -19,7 +18,7 @@ public class BaseMalariaRegisterPresenterTest { protected BaseMalariaRegisterPresenter baseMalariaRegisterPresenter; @Mock - protected BaseRegisterContract.View baseView; + protected MalariaRegisterContract.View baseView; @Before public void setUp() { @@ -32,11 +31,11 @@ public void startFormWhenEntityIdIsNull() throws Exception { Mockito.verify(baseView, Mockito.never()).startFormActivity(null); } - @Test - public void startFormWhenEntityIdIsNotNull() throws Exception { - baseMalariaRegisterPresenter.startForm("formName", "12131212", "121212121212", "231231231231"); - PowerMockito.verifyPrivate(baseMalariaRegisterPresenter).invoke("getView"); - } +// @Test +// public void startFormWhenEntityIdIsNotNull() throws Exception { +// baseMalariaRegisterPresenter.startForm("formName", "12131212", "121212121212", "231231231231"); +// PowerMockito.verifyPrivate(baseMalariaRegisterPresenter).invoke("getView"); +// } @Test public void startFormWithEntityId() throws Exception { From 0a8795e865c4755edb3efc4bbaf0de601e74d49c Mon Sep 17 00:00:00 2001 From: Denis rwelamila Date: Thu, 10 Oct 2019 11:34:41 +0300 Subject: [PATCH 17/19] Update BaseMalariaRegisterPresenterTest.java --- .../presenter/BaseMalariaRegisterPresenterTest.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java index 0770917..7068f88 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java @@ -31,23 +31,12 @@ public void startFormWhenEntityIdIsNull() throws Exception { Mockito.verify(baseView, Mockito.never()).startFormActivity(null); } -// @Test -// public void startFormWhenEntityIdIsNotNull() throws Exception { -// baseMalariaRegisterPresenter.startForm("formName", "12131212", "121212121212", "231231231231"); -// PowerMockito.verifyPrivate(baseMalariaRegisterPresenter).invoke("getView"); -// } - @Test public void startFormWithEntityId() throws Exception { baseMalariaRegisterPresenter.startForm("formName", "12121212", "121212121212", "231231231231"); Mockito.verify(baseView, Mockito.never()).startFormActivity(new JSONObject()); } -// @Test -// public void saveForm() { -// baseMalariaRegisterPresenter.saveForm("{}"); -// Mockito.verify(baseView).showProgressDialog(1); -// } @Test public void getViewWhenViewIsNull() throws Exception { From 64228777e0ca287a8d2d89a440335c5177db76f3 Mon Sep 17 00:00:00 2001 From: Denis R Date: Thu, 10 Oct 2019 15:33:27 +0300 Subject: [PATCH 18/19] more tests for BaseMalariaRegisterPresenter --- .../BaseMalariaRegisterPresenterTest.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java index 0770917..bdcd046 100644 --- a/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/presenter/BaseMalariaRegisterPresenterTest.java @@ -12,46 +12,56 @@ import org.smartregister.chw.malaria.contract.MalariaRegisterContract; import org.smartregister.chw.malaria.presenter.BaseMalariaRegisterPresenter; + @PrepareForTest(BaseMalariaRegisterPresenter.class) public class BaseMalariaRegisterPresenterTest { @Mock protected BaseMalariaRegisterPresenter baseMalariaRegisterPresenter; + @Mock + protected MalariaRegisterContract.Interactor interactor; + @Mock + protected MalariaRegisterContract.Model model; @Mock protected MalariaRegisterContract.View baseView; + private BaseMalariaRegisterPresenter presenter; @Before public void setUp() { MockitoAnnotations.initMocks(this); + presenter = new BaseMalariaRegisterPresenter(baseView, model, interactor); } @Test public void startFormWhenEntityIdIsNull() throws Exception { - baseMalariaRegisterPresenter.startForm("formName", "", "121212121212", "231231231231"); + presenter.startForm("formName", "", "121212121212", "231231231231"); Mockito.verify(baseView, Mockito.never()).startFormActivity(null); } -// @Test -// public void startFormWhenEntityIdIsNotNull() throws Exception { -// baseMalariaRegisterPresenter.startForm("formName", "12131212", "121212121212", "231231231231"); -// PowerMockito.verifyPrivate(baseMalariaRegisterPresenter).invoke("getView"); -// } - @Test - public void startFormWithEntityId() throws Exception { - baseMalariaRegisterPresenter.startForm("formName", "12121212", "121212121212", "231231231231"); - Mockito.verify(baseView, Mockito.never()).startFormActivity(new JSONObject()); + public void startFormWhenEntityIdIsNotNull() throws Exception { + JSONObject form = model.getFormAsJson("formName", "12131212", "231231231231"); + Mockito.when(model.getFormAsJson("formName", "12131212", "231231231231")).thenReturn(form); + Mockito.doNothing().when(baseView).startFormActivity(form); + presenter.startForm("formName", "12131212", "121212121212", "231231231231"); + Mockito.verify(baseView).startFormActivity(form); } -// @Test -// public void saveForm() { -// baseMalariaRegisterPresenter.saveForm("{}"); -// Mockito.verify(baseView).showProgressDialog(1); -// } + @Test + public void saveForm() { + presenter.saveForm("{}"); + Mockito.verify(interactor).saveRegistration("{}", presenter); + } @Test public void getViewWhenViewIsNull() throws Exception { Assert.assertNull(Whitebox.invokeMethod(baseMalariaRegisterPresenter, "getView")); } + @Test + public void onRegistrationSaved() { + presenter.onRegistrationSaved(); + Mockito.verify(baseView).hideProgressDialog(); + } + } From ff4c5fbb320662cc360f227ac44843bee0715ed4 Mon Sep 17 00:00:00 2001 From: Denis R Date: Fri, 11 Oct 2019 08:59:33 +0300 Subject: [PATCH 19/19] trigger coveralls --- .../model/BaseMalariaRegisterFragmentModelTest.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 opensrp-chw-malaria/src/test/java/org/smartregister/model/BaseMalariaRegisterFragmentModelTest.java diff --git a/opensrp-chw-malaria/src/test/java/org/smartregister/model/BaseMalariaRegisterFragmentModelTest.java b/opensrp-chw-malaria/src/test/java/org/smartregister/model/BaseMalariaRegisterFragmentModelTest.java new file mode 100644 index 0000000..bc2d476 --- /dev/null +++ b/opensrp-chw-malaria/src/test/java/org/smartregister/model/BaseMalariaRegisterFragmentModelTest.java @@ -0,0 +1,4 @@ +package org.smartregister.model; + +public class BaseMalariaRegisterFragmentModelTest { +}