Skip to content

Commit

Permalink
add tests for date fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LZRS committed Oct 4, 2021
1 parent 84941d1 commit 5342eaa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'});
}
}
Original file line number Diff line number Diff line change
@@ -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'}));
}


}

0 comments on commit 5342eaa

Please sign in to comment.