Created
August 25, 2017 07:41
-
-
Save mgdiez/7634a08e97dd6af0d3337023d1284e6a to your computer and use it in GitHub Desktop.
Dummy method mocking ConnectivityManager from Context with Mockito
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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