Search in sources :

Example 31 with NetworkInfo

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;
}
Also used : NetworkInfo(android.net.NetworkInfo)

Example 32 with NetworkInfo

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();
}
Also used : NetworkInfo(android.net.NetworkInfo) TestUtils.mockNetworkInfo(com.squareup.picasso.TestUtils.mockNetworkInfo) Test(org.junit.Test)

Example 33 with NetworkInfo

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);
}
Also used : NetworkInfo(android.net.NetworkInfo) TestUtils.mockNetworkInfo(com.squareup.picasso.TestUtils.mockNetworkInfo) ConnectivityManager(android.net.ConnectivityManager) Intent(android.content.Intent) NetworkBroadcastReceiver(com.squareup.picasso.Dispatcher.NetworkBroadcastReceiver) Test(org.junit.Test)

Example 34 with 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);
}
Also used : TestUtils.mockAction(com.squareup.picasso.TestUtils.mockAction) NetworkInfo(android.net.NetworkInfo) TestUtils.mockNetworkInfo(com.squareup.picasso.TestUtils.mockNetworkInfo) Test(org.junit.Test)

Example 35 with NetworkInfo

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();
}
Also used : TestUtils.mockAction(com.squareup.picasso.TestUtils.mockAction) NetworkInfo(android.net.NetworkInfo) TestUtils.mockNetworkInfo(com.squareup.picasso.TestUtils.mockNetworkInfo) Test(org.junit.Test)

Aggregations

NetworkInfo (android.net.NetworkInfo)511 ConnectivityManager (android.net.ConnectivityManager)274 Intent (android.content.Intent)47 LinkProperties (android.net.LinkProperties)38 NetworkState (android.net.NetworkState)26 Test (org.junit.Test)26 PendingIntent (android.app.PendingIntent)23 NetworkCapabilities (android.net.NetworkCapabilities)18 Network (android.net.Network)17 LargeTest (android.test.suitebuilder.annotation.LargeTest)17 RemoteException (android.os.RemoteException)16 Context (android.content.Context)15 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)15 WifiInfo (android.net.wifi.WifiInfo)13 Bundle (android.os.Bundle)13 TestUtils.mockNetworkInfo (com.squareup.picasso.TestUtils.mockNetworkInfo)12 IOException (java.io.IOException)11 WifiManager (android.net.wifi.WifiManager)9 IntentFilter (android.content.IntentFilter)8 BroadcastReceiver (android.content.BroadcastReceiver)7