diff --git a/android/src/test/java/io/grpc/android/AndroidChannelBuilderTest.java b/android/src/test/java/io/grpc/android/AndroidChannelBuilderTest.java index c0884e4d7cf..be49ea838bf 100644 --- a/android/src/test/java/io/grpc/android/AndroidChannelBuilderTest.java +++ b/android/src/test/java/io/grpc/android/AndroidChannelBuilderTest.java @@ -24,7 +24,6 @@ import static org.robolectric.annotation.LooperMode.Mode.LEGACY; import android.content.Context; -import android.content.Intent; import android.net.ConnectivityManager; import android.net.Network; import androidx.test.core.app.ApplicationProvider; @@ -105,22 +104,6 @@ public void usingBuilderConstructor() { assertThat(androidBuilder.delegate()).isSameInstanceAs(wrappedBuilder); } - @Test - @Config(sdk = 23) - public void nullContextDoesNotThrow_api23() { - TestChannel delegateChannel = new TestChannel(); - ManagedChannel androidChannel = new AndroidChannelBuilder.AndroidChannel(delegateChannel, null); - - // Network change and shutdown should be no-op for the channel without an Android Context - shadowOf(connectivityManager).setActiveNetworkInfo(WIFI_CONNECTED); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - androidChannel.shutdown(); - - assertThat(delegateChannel.enterIdleCount).isEqualTo(0); - } - @Test @Config(sdk = 24) public void nullContextDoesNotThrow_api24() { @@ -135,59 +118,6 @@ public void nullContextDoesNotThrow_api24() { assertThat(delegateChannel.enterIdleCount).isEqualTo(0); } - @Test - @Config(sdk = 23) - public void networkChanges_api23() { - TestChannel delegateChannel = new TestChannel(); - ManagedChannel androidChannel = - new AndroidChannelBuilder.AndroidChannel( - delegateChannel, ApplicationProvider.getApplicationContext()); - assertThat(delegateChannel.enterIdleCount).isEqualTo(0); - - // On API levels < 24, the broadcast receiver will invoke enterIdle() on the first - // connectivity action broadcast regardless of previous connection status - shadowOf(connectivityManager).setActiveNetworkInfo(WIFI_CONNECTED); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - assertThat(delegateChannel.enterIdleCount).isEqualTo(1); - - // Drop the connection - shadowOf(connectivityManager).setActiveNetworkInfo(null); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - assertThat(delegateChannel.enterIdleCount).isEqualTo(1); - - // Notify that a new but not connected network is available - shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_DISCONNECTED); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - assertThat(delegateChannel.enterIdleCount).isEqualTo(1); - - // Establish a connection - shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_CONNECTED); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - assertThat(delegateChannel.enterIdleCount).isEqualTo(2); - - // Disconnect, then shutdown the channel and verify that the broadcast receiver has been - // unregistered - shadowOf(connectivityManager).setActiveNetworkInfo(null); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - androidChannel.shutdown(); - shadowOf(connectivityManager).setActiveNetworkInfo(MOBILE_CONNECTED); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - - assertThat(delegateChannel.enterIdleCount).isEqualTo(2); - } - @Test @Config(sdk = 24) public void networkChanges_api24() { @@ -223,27 +153,6 @@ public void networkChanges_api24() { assertThat(delegateChannel.enterIdleCount).isEqualTo(3); } - @Test - @Config(sdk = 23) - public void shutdownNowUnregistersBroadcastReceiver_api23() { - TestChannel delegateChannel = new TestChannel(); - ManagedChannel androidChannel = - new AndroidChannelBuilder.AndroidChannel( - delegateChannel, ApplicationProvider.getApplicationContext()); - - shadowOf(connectivityManager).setActiveNetworkInfo(null); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - androidChannel.shutdownNow(); - shadowOf(connectivityManager).setActiveNetworkInfo(WIFI_CONNECTED); - ApplicationProvider - .getApplicationContext() - .sendBroadcast(new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); - - assertThat(delegateChannel.enterIdleCount).isEqualTo(0); - } - @Test @Config(sdk = 24) public void shutdownNowUnregistersNetworkCallback_api24() {