From 5342eaa4abba084a80addd6493e9551df5150e05 Mon Sep 17 00:00:00 2001 From: LZRS <12814349+LZRS@users.noreply.github.com> Date: Tue, 21 Sep 2021 15:02:11 +0300 Subject: [PATCH] add tests for date fix --- .../BaseHomeVisitImmunizationFragmentFlv.java | 10 ++++-- ...eHomeVisitImmunizationFragmentFlvTest.java | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 opensrp-chw/src/testLmh/java/org/smartregister/chw/fragment/BaseHomeVisitImmunizationFragmentFlvTest.java diff --git a/opensrp-chw/src/lmh/java/org/smartregister/chw/fragment/BaseHomeVisitImmunizationFragmentFlv.java b/opensrp-chw/src/lmh/java/org/smartregister/chw/fragment/BaseHomeVisitImmunizationFragmentFlv.java index a5c658729f..16ae4d30cf 100644 --- a/opensrp-chw/src/lmh/java/org/smartregister/chw/fragment/BaseHomeVisitImmunizationFragmentFlv.java +++ b/opensrp-chw/src/lmh/java/org/smartregister/chw/fragment/BaseHomeVisitImmunizationFragmentFlv.java @@ -6,6 +6,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; import org.smartregister.chw.anc.contract.BaseAncHomeVisitContract; import org.smartregister.chw.anc.domain.VaccineDisplay; @@ -43,12 +44,17 @@ public static BaseHomeVisitImmunizationFragmentFlv getInstance(final BaseAncHome @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - DatePickerUtils.themeDatePicker(singleDatePicker, new char[]{'d', 'm', 'y'}); + callDatePickerUtilsThemeDatePicker(singleDatePicker, new char[]{'d', 'm', 'y'}); super.onViewCreated(view, savedInstanceState); } + @VisibleForTesting + void callDatePickerUtilsThemeDatePicker(DatePicker datePicker, char[] ymdOrder){ + DatePickerUtils.themeDatePicker(datePicker, ymdOrder); + } + @Override protected void setDatePickerTheme(DatePicker picker) { - DatePickerUtils.themeDatePicker(picker, new char[]{'d', 'm', 'y'}); + callDatePickerUtilsThemeDatePicker(picker, new char[]{'d', 'm', 'y'}); } } diff --git a/opensrp-chw/src/testLmh/java/org/smartregister/chw/fragment/BaseHomeVisitImmunizationFragmentFlvTest.java b/opensrp-chw/src/testLmh/java/org/smartregister/chw/fragment/BaseHomeVisitImmunizationFragmentFlvTest.java new file mode 100644 index 0000000000..79d5e27491 --- /dev/null +++ b/opensrp-chw/src/testLmh/java/org/smartregister/chw/fragment/BaseHomeVisitImmunizationFragmentFlvTest.java @@ -0,0 +1,36 @@ +package org.smartregister.chw.fragment; + +import android.widget.DatePicker; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.AdditionalMatchers; +import org.mockito.Spy; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.MockitoAnnotations.initMocks; + +public class BaseHomeVisitImmunizationFragmentFlvTest { + + @Spy + BaseHomeVisitImmunizationFragmentFlv fragmentFlv; + + @Before + public void setUp(){ + initMocks(this); + } + + @Test + public void testSetDatePickerThemeSetsCorrectFormat() { + DatePicker datePicker = mock(DatePicker.class); + doNothing().when(fragmentFlv).callDatePickerUtilsThemeDatePicker(any(), any()); + fragmentFlv.setDatePickerTheme(datePicker); + verify(fragmentFlv).callDatePickerUtilsThemeDatePicker(eq(datePicker), AdditionalMatchers.aryEq(new char[]{'d', 'm', 'y'})); + } + + +}