From 04f85711595bd856d27fe6c3754ee42822cfbc0a Mon Sep 17 00:00:00 2001 From: LZRS Date: Tue, 6 Apr 2021 16:42:14 +0300 Subject: [PATCH] Test onShowOperationalAreaSelector shows error should show when extractLocationHierarchy returns null linked to #1226 --- .../reveal/presenter/BaseDrawerPresenter.java | 2 +- .../presenter/BaseDrawerPresenterTest.java | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/opensrp-reveal/src/main/java/org/smartregister/reveal/presenter/BaseDrawerPresenter.java b/opensrp-reveal/src/main/java/org/smartregister/reveal/presenter/BaseDrawerPresenter.java index 8bfa4fe915..703ae5dd7e 100644 --- a/opensrp-reveal/src/main/java/org/smartregister/reveal/presenter/BaseDrawerPresenter.java +++ b/opensrp-reveal/src/main/java/org/smartregister/reveal/presenter/BaseDrawerPresenter.java @@ -176,7 +176,7 @@ private void populateLocationsFromPreferences() { @Override public void onShowOperationalAreaSelector() { Pair> locationHierarchy = extractLocationHierarchy(); - if (locationHierarchy == null) {//try to evict location hierachy in cache + if (locationHierarchy == null) {//try to evict location hierarchy in cache revealApplication.getContext().anmLocationController().evict(); locationHierarchy = extractLocationHierarchy(); } diff --git a/opensrp-reveal/src/test/java/org/smartregister/reveal/presenter/BaseDrawerPresenterTest.java b/opensrp-reveal/src/test/java/org/smartregister/reveal/presenter/BaseDrawerPresenterTest.java index ca4abd9cd5..ddd1cf0b4e 100644 --- a/opensrp-reveal/src/test/java/org/smartregister/reveal/presenter/BaseDrawerPresenterTest.java +++ b/opensrp-reveal/src/test/java/org/smartregister/reveal/presenter/BaseDrawerPresenterTest.java @@ -37,7 +37,9 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -86,7 +88,7 @@ public class BaseDrawerPresenterTest extends BaseUnitTest { private ArgumentCaptor entireTreeString; @Captor - private ArgumentCaptor> arrayListArgumentCaptor; + private ArgumentCaptor> arrayListArgumentCaptor; @Captor private ArgumentCaptor>> pairArgumentCaptor; @@ -298,7 +300,7 @@ public void testOnViewResumedWithViewInitialized() { } @Test - public void testIsChangedCurrentSelectio() { + public void testIsChangedCurrentSelection() { Whitebox.setInternalState(presenter, "changedCurrentSelection", true); boolean actualIsChangedCurrentSelection = presenter.isChangedCurrentSelection(); @@ -307,7 +309,7 @@ public void testIsChangedCurrentSelectio() { } @Test - public void testSetChangedCurrentSelectio() { + public void testSetChangedCurrentSelection() { assertFalse(Whitebox.getInternalState(presenter, "changedCurrentSelection")); presenter.setChangedCurrentSelection(true); @@ -316,7 +318,7 @@ public void testSetChangedCurrentSelectio() { } @Test - public void testOnDraweClosed() { + public void testOnDrawerClosed() { presenter.onDrawerClosed(); verify(drawerActivity).onDrawerClosed(); } @@ -350,6 +352,16 @@ public void testOnPlanSelectorClicked() { assertTrue(Whitebox.getInternalState(presenter, "changedCurrentSelection")); } + @Test + public void testOnShowOperationalAreaSelectorNullShowsErrorProcessingHierarchy(){ + Whitebox.setInternalState(presenter, "locationHelper", locationHelper); + when(locationHelper.generateDefaultLocationHierarchy(anyList())) + .thenReturn(null); + presenter.onShowOperationalAreaSelector(); + verify(locationHelper, times(2)).generateDefaultLocationHierarchy(anyList()); + verify(view).displayNotification(eq(R.string.error_fetching_location_hierarchy_title), eq(R.string.error_fetching_location_hierarchy)); + } + @Test public void testOnShowOperationalAreaSelector() { when(preferencesUtil.getPreferenceValue(anyString())).thenReturn("akros_1");