From ac2e593d04322c3e2ed6b2974a107833e2e435dd Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Fri, 22 Jan 2021 15:52:25 +0500 Subject: [PATCH 1/7] Fix recurring vaccines string comparison --- .../smartregister/immunization/adapter/ServiceRowAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java index 33f2d2f6..2ca127da 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java @@ -159,7 +159,7 @@ public void updateWrapper(ServiceWrapper tag) { if (!serviceRecordList.isEmpty()) { for (ServiceRecord serviceRecord : serviceRecordList) { - if (tag.getName().toLowerCase().contains(serviceRecord.getName().toLowerCase()) && serviceRecord + if (tag.getName().toLowerCase().equalsIgnoreCase(serviceRecord.getName().toLowerCase()) && serviceRecord .getDate() != null) { long diff = serviceRecord.getUpdatedAt() - serviceRecord.getDate().getTime(); if (diff > 0 && TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) > 1) { From bb69f41be7a18a17684e36c083e06a8f31753695 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Fri, 22 Jan 2021 16:06:39 +0500 Subject: [PATCH 2/7] Fix codacy static code analysis tests --- .../smartregister/immunization/adapter/ServiceRowAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java index 2ca127da..95ac0ec3 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ServiceRowAdapter.java @@ -159,7 +159,7 @@ public void updateWrapper(ServiceWrapper tag) { if (!serviceRecordList.isEmpty()) { for (ServiceRecord serviceRecord : serviceRecordList) { - if (tag.getName().toLowerCase().equalsIgnoreCase(serviceRecord.getName().toLowerCase()) && serviceRecord + if (tag.getName().equalsIgnoreCase(serviceRecord.getName()) && serviceRecord .getDate() != null) { long diff = serviceRecord.getUpdatedAt() - serviceRecord.getDate().getTime(); if (diff > 0 && TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS) > 1) { From 9f7333c33838b681ae03a8ad28bfcd1e6af0529d Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Tue, 26 Jan 2021 11:42:34 +0500 Subject: [PATCH 3/7] Hide row with no vaccine date --- .../adapter/ImmunizationRowAdapter.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java index 4cec537d..9282c6d1 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java @@ -264,7 +264,25 @@ protected VaccineWrapper doInBackground(Void... params) { protected void onPostExecute(VaccineWrapper vaccineWrapper) { vaccineCard.setVaccineWrapper(vaccineWrapper); vaccineGroup.toggleRecordAllTV(); - notifyDataSetChanged(); + if (vaccineWrapper.getStatus() == null) { + removeVaccine(vaccineName, vaccineWrapper); + } else { + notifyDataSetChanged(); + } + } + } + + private void removeVaccine(String vaccineName, VaccineWrapper vaccineWrapper) { + vaccineCards.remove(vaccineName); + for (int i = 0; i < vaccineGroup.getVaccineData().vaccines.size(); i++) { + org.smartregister.immunization.domain.jsonmapping.Vaccine vaccine = vaccineGroup.getVaccineData().vaccines + .get(i); + if (vaccine.getName().equalsIgnoreCase(vaccineName)) { + vaccineGroup.getVaccineData().vaccines + .remove(i); + } } + notifyDataSetChanged(); + vaccineGroup.getVaccinesGV().invalidateViews(); } } From ea897ce34456e64c1610aa2b521ec881e617ee36 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Tue, 26 Jan 2021 13:31:30 +0500 Subject: [PATCH 4/7] Fix codacy test --- .../immunization/adapter/ImmunizationRowAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java index 9282c6d1..c7e3aa8f 100644 --- a/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java +++ b/opensrp-immunization/src/main/java/org/smartregister/immunization/adapter/ImmunizationRowAdapter.java @@ -265,14 +265,14 @@ protected void onPostExecute(VaccineWrapper vaccineWrapper) { vaccineCard.setVaccineWrapper(vaccineWrapper); vaccineGroup.toggleRecordAllTV(); if (vaccineWrapper.getStatus() == null) { - removeVaccine(vaccineName, vaccineWrapper); + removeVaccine(vaccineName); } else { notifyDataSetChanged(); } } } - private void removeVaccine(String vaccineName, VaccineWrapper vaccineWrapper) { + private void removeVaccine(String vaccineName) { vaccineCards.remove(vaccineName); for (int i = 0; i < vaccineGroup.getVaccineData().vaccines.size(); i++) { org.smartregister.immunization.domain.jsonmapping.Vaccine vaccine = vaccineGroup.getVaccineData().vaccines From 339818dc800a2951317c6a23986fd94d19ecfdd1 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Tue, 26 Jan 2021 16:38:25 +0500 Subject: [PATCH 5/7] Increase test coverage --- .../adapter/ImmunizationRowAdapterTest.java | 23 ++++++++++++++++++- .../view/ServiceRowGroupTest.java | 8 +++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index 343ff2d6..00c1398d 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -10,10 +10,12 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; +import org.robolectric.util.ReflectionHelpers; import org.smartregister.commonregistry.CommonPersonObjectClient; import org.smartregister.domain.Alert; import org.smartregister.domain.AlertStatus; @@ -27,7 +29,9 @@ import org.smartregister.immunization.domain.VaccineWrapper; import org.smartregister.immunization.domain.jsonmapping.VaccineGroup; import org.smartregister.immunization.repository.VaccineRepository; +import org.smartregister.immunization.view.ImmunizationRowCard; import org.smartregister.immunization.view.ImmunizationRowGroup; +import org.smartregister.immunization.view.VaccineCard; import org.smartregister.util.JsonFormUtils; import java.lang.reflect.Type; @@ -81,6 +85,11 @@ public void setDataForTest(String dateTimeString) { wrapper.setName(VaccineRepo.Vaccine.measles2.display()); wrapper.setVaccine(VaccineRepo.Vaccine.measles2); wrappers.add(wrapper); + wrapper.setDbKey(0l); + wrapper.setName(VaccineRepo.Vaccine.opv0.display()); + wrapper.setVaccine(VaccineRepo.Vaccine.opv0); + wrapper.setStatus(null); + wrappers.add(wrapper); Type listType = new TypeToken>() { }.getType(); @@ -141,8 +150,20 @@ public void assertGetViewReturnsVaccineGroup() { ImmunizationRowAdapter immunizationRowAdapter = new ImmunizationRowAdapter(RuntimeEnvironment.application, view, true, vaccinelist, alertlist); - Assert.assertEquals(immunizationRowAdapter.getView(0, null, null) != null, true); + Assert.assertNotNull(immunizationRowAdapter.getView(0, null, null)); + + } + + @Test + public void assertVaccineRemovedWithNullStatus() { + ImmunizationRowAdapter mockAdapter = Mockito + .spy(new ImmunizationRowAdapter(context, view, true, vaccinelist, alertlist)); + + ReflectionHelpers.callInstanceMethod(mockAdapter, "removeVaccine", + ReflectionHelpers.ClassParameter.from(String.class, "OPV 0")); + + Assert.assertEquals(view.getVaccineData().vaccines.size(), 1); } } diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/view/ServiceRowGroupTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/view/ServiceRowGroupTest.java index 4794efa2..d1968fb8 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/view/ServiceRowGroupTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/view/ServiceRowGroupTest.java @@ -75,6 +75,14 @@ public void assertConstructorsNotNull() { //Assert.assertNotNull(activity.getInstance3()); } + @Test + public void testConstructors() { + Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application)); + Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build())); + Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build(), 0)); + Assert.assertNotNull(new ServiceRowGroup(RuntimeEnvironment.application, Robolectric.buildAttributeSet().build(), 0, 0)); + } + @After public void tearDown() { destroyController(); From 262fe0952e2adf1501d58dbc41cb4a7c21249fc2 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Tue, 26 Jan 2021 16:44:33 +0500 Subject: [PATCH 6/7] Fix codacy test --- .../immunization/adapter/ImmunizationRowAdapterTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java index 00c1398d..eb36aee6 100644 --- a/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java +++ b/opensrp-immunization/src/test/java/org/smartregister/immunization/adapter/ImmunizationRowAdapterTest.java @@ -29,9 +29,7 @@ import org.smartregister.immunization.domain.VaccineWrapper; import org.smartregister.immunization.domain.jsonmapping.VaccineGroup; import org.smartregister.immunization.repository.VaccineRepository; -import org.smartregister.immunization.view.ImmunizationRowCard; import org.smartregister.immunization.view.ImmunizationRowGroup; -import org.smartregister.immunization.view.VaccineCard; import org.smartregister.util.JsonFormUtils; import java.lang.reflect.Type; From 67034a7a365e9b231260d50a8627abca06c27836 Mon Sep 17 00:00:00 2001 From: Hamza Ahmed Khan Date: Tue, 26 Jan 2021 16:55:14 +0500 Subject: [PATCH 7/7] Bumped up library version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 605c069d..f4cbe66a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=3.0.4-SNAPSHOT +VERSION_NAME=3.0.5-SNAPSHOT VERSION_CODE=2 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Immunization