2424import static org .robolectric .annotation .LooperMode .Mode .LEGACY ;
2525
2626import android .content .Context ;
27- import android .content .Intent ;
2827import android .net .ConnectivityManager ;
2928import android .net .Network ;
3029import androidx .test .core .app .ApplicationProvider ;
@@ -105,22 +104,6 @@ public void usingBuilderConstructor() {
105104 assertThat (androidBuilder .delegate ()).isSameInstanceAs (wrappedBuilder );
106105 }
107106
108- @ Test
109- @ Config (sdk = 23 )
110- public void nullContextDoesNotThrow_api23 () {
111- TestChannel delegateChannel = new TestChannel ();
112- ManagedChannel androidChannel = new AndroidChannelBuilder .AndroidChannel (delegateChannel , null );
113-
114- // Network change and shutdown should be no-op for the channel without an Android Context
115- shadowOf (connectivityManager ).setActiveNetworkInfo (WIFI_CONNECTED );
116- ApplicationProvider
117- .getApplicationContext ()
118- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
119- androidChannel .shutdown ();
120-
121- assertThat (delegateChannel .enterIdleCount ).isEqualTo (0 );
122- }
123-
124107 @ Test
125108 @ Config (sdk = 24 )
126109 public void nullContextDoesNotThrow_api24 () {
@@ -135,59 +118,6 @@ public void nullContextDoesNotThrow_api24() {
135118 assertThat (delegateChannel .enterIdleCount ).isEqualTo (0 );
136119 }
137120
138- @ Test
139- @ Config (sdk = 23 )
140- public void networkChanges_api23 () {
141- TestChannel delegateChannel = new TestChannel ();
142- ManagedChannel androidChannel =
143- new AndroidChannelBuilder .AndroidChannel (
144- delegateChannel , ApplicationProvider .getApplicationContext ());
145- assertThat (delegateChannel .enterIdleCount ).isEqualTo (0 );
146-
147- // On API levels < 24, the broadcast receiver will invoke enterIdle() on the first
148- // connectivity action broadcast regardless of previous connection status
149- shadowOf (connectivityManager ).setActiveNetworkInfo (WIFI_CONNECTED );
150- ApplicationProvider
151- .getApplicationContext ()
152- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
153- assertThat (delegateChannel .enterIdleCount ).isEqualTo (1 );
154-
155- // Drop the connection
156- shadowOf (connectivityManager ).setActiveNetworkInfo (null );
157- ApplicationProvider
158- .getApplicationContext ()
159- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
160- assertThat (delegateChannel .enterIdleCount ).isEqualTo (1 );
161-
162- // Notify that a new but not connected network is available
163- shadowOf (connectivityManager ).setActiveNetworkInfo (MOBILE_DISCONNECTED );
164- ApplicationProvider
165- .getApplicationContext ()
166- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
167- assertThat (delegateChannel .enterIdleCount ).isEqualTo (1 );
168-
169- // Establish a connection
170- shadowOf (connectivityManager ).setActiveNetworkInfo (MOBILE_CONNECTED );
171- ApplicationProvider
172- .getApplicationContext ()
173- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
174- assertThat (delegateChannel .enterIdleCount ).isEqualTo (2 );
175-
176- // Disconnect, then shutdown the channel and verify that the broadcast receiver has been
177- // unregistered
178- shadowOf (connectivityManager ).setActiveNetworkInfo (null );
179- ApplicationProvider
180- .getApplicationContext ()
181- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
182- androidChannel .shutdown ();
183- shadowOf (connectivityManager ).setActiveNetworkInfo (MOBILE_CONNECTED );
184- ApplicationProvider
185- .getApplicationContext ()
186- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
187-
188- assertThat (delegateChannel .enterIdleCount ).isEqualTo (2 );
189- }
190-
191121 @ Test
192122 @ Config (sdk = 24 )
193123 public void networkChanges_api24 () {
@@ -223,27 +153,6 @@ public void networkChanges_api24() {
223153 assertThat (delegateChannel .enterIdleCount ).isEqualTo (3 );
224154 }
225155
226- @ Test
227- @ Config (sdk = 23 )
228- public void shutdownNowUnregistersBroadcastReceiver_api23 () {
229- TestChannel delegateChannel = new TestChannel ();
230- ManagedChannel androidChannel =
231- new AndroidChannelBuilder .AndroidChannel (
232- delegateChannel , ApplicationProvider .getApplicationContext ());
233-
234- shadowOf (connectivityManager ).setActiveNetworkInfo (null );
235- ApplicationProvider
236- .getApplicationContext ()
237- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
238- androidChannel .shutdownNow ();
239- shadowOf (connectivityManager ).setActiveNetworkInfo (WIFI_CONNECTED );
240- ApplicationProvider
241- .getApplicationContext ()
242- .sendBroadcast (new Intent (ConnectivityManager .CONNECTIVITY_ACTION ));
243-
244- assertThat (delegateChannel .enterIdleCount ).isEqualTo (0 );
245- }
246-
247156 @ Test
248157 @ Config (sdk = 24 )
249158 public void shutdownNowUnregistersNetworkCallback_api24 () {
0 commit comments