Skip to content

Instantly share code, notes, and snippets.

@mgdiez
Created August 25, 2017 07:41
Show Gist options
  • Save mgdiez/7634a08e97dd6af0d3337023d1284e6a to your computer and use it in GitHub Desktop.
Save mgdiez/7634a08e97dd6af0d3337023d1284e6a to your computer and use it in GitHub Desktop.
Dummy method mocking ConnectivityManager from Context with Mockito
@Test public void navigate_to_splash_on_save_if_has_changes() {
when(mockApplicationPreferences.getCountry()).thenReturn("fake");
when(mockApplicationPreferences.getLanguage()).thenReturn("fake");
ConnectivityManager mockConnectivityManager = Mockito.mock(ConnectivityManager.class);
when(mockContext.getSystemService(anyString())).thenReturn(mockConnectivityManager);
NetworkInfo mockNetworkInfo = Mockito.mock(NetworkInfo.class);
when(mockConnectivityManager.getActiveNetworkInfo()).thenReturn(mockNetworkInfo);
when(mockNetworkInfo.isConnectedOrConnecting()).thenReturn(true);
when(mockPreferencesView.getContext()).thenReturn(mockContext);
preferencesPresenter.onSaveDialogOK();
verify(mockStoryController).navigateToSplash(any());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment