use of android.net.NetworkInfo in project picasso by square.
the class TestUtils method mockNetworkInfo.
static NetworkInfo mockNetworkInfo(boolean isConnected) {
NetworkInfo mock = mock(NetworkInfo.class);
when(mock.isConnected()).thenReturn(isConnected);
when(mock.isConnectedOrConnecting()).thenReturn(isConnected);
return mock;
}
use of android.net.NetworkInfo in project picasso by square.
the class NetworkRequestHandlerTest method shouldRetryWithConnectedNetworkInfo.
@Test
public void shouldRetryWithConnectedNetworkInfo() throws Exception {
NetworkInfo info = mockNetworkInfo();
when(info.isConnected()).thenReturn(true);
assertThat(networkHandler.shouldRetry(false, info)).isTrue();
assertThat(networkHandler.shouldRetry(true, info)).isTrue();
}
use of android.net.NetworkInfo in project picasso by square.
the class DispatcherTest method nullExtrasOnReceiveConnectivityAreOk.
@Test
public void nullExtrasOnReceiveConnectivityAreOk() {
ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
NetworkInfo networkInfo = mockNetworkInfo();
when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
when(context.getSystemService(CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);
Dispatcher dispatcher = mock(Dispatcher.class);
NetworkBroadcastReceiver receiver = new NetworkBroadcastReceiver(dispatcher);
receiver.onReceive(context, new Intent(CONNECTIVITY_ACTION));
verify(dispatcher).dispatchNetworkStateChange(networkInfo);
}
use of android.net.NetworkInfo in project picasso by square.
the class DispatcherTest method performRetryMarksForReplayIfSupportedScansNetworkChangesAndShouldNotRetry.
@Test
public void performRetryMarksForReplayIfSupportedScansNetworkChangesAndShouldNotRetry() {
NetworkInfo networkInfo = mockNetworkInfo(true);
Action action = mockAction(URI_KEY_1, URI_1, mockTarget());
BitmapHunter hunter = mockHunter(URI_KEY_1, bitmap1, false, action);
when(hunter.supportsReplay()).thenReturn(true);
when(hunter.shouldRetry(anyBoolean(), any(NetworkInfo.class))).thenReturn(false);
when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
dispatcher.performRetry(hunter);
assertThat(dispatcher.hunterMap).isEmpty();
assertThat(dispatcher.failedActions).hasSize(1);
verify(service, never()).submit(hunter);
}
use of android.net.NetworkInfo in project picasso by square.
the class DispatcherTest method performNetworkStateChangeFlushesFailedHunters.
@Test
public void performNetworkStateChangeFlushesFailedHunters() {
PicassoExecutorService service = mock(PicassoExecutorService.class);
NetworkInfo info = mockNetworkInfo(true);
Dispatcher dispatcher = createDispatcher(service);
Action failedAction1 = mockAction(URI_KEY_1, URI_1);
Action failedAction2 = mockAction(URI_KEY_2, URI_2);
dispatcher.failedActions.put(URI_KEY_1, failedAction1);
dispatcher.failedActions.put(URI_KEY_2, failedAction2);
dispatcher.performNetworkStateChange(info);
verify(service, times(2)).submit(any(BitmapHunter.class));
assertThat(dispatcher.failedActions).isEmpty();
}
Aggregations