This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[connectivity] Fix IllegalArgumentException (#3235)
* IllegalArgumentException * IllegalArgumentException * Update ConnectivityBroadcastReceiver.java * Add onConnectivityChanged Test * Format * Format * Test registerDefaultNetworkCallback * Format * Format * null != networkCallback
- Loading branch information
1 parent
b597aba
commit da36984
Showing
9 changed files
with
88 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
53 changes: 53 additions & 0 deletions
53
...xample/android/app/src/test/java/io/flutter/plugins/connectivityexample/ActivityTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.flutter.plugins.connectivityexample; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.spy; | ||
|
||
import android.content.Context; | ||
import android.net.ConnectivityManager; | ||
import io.flutter.plugins.connectivity.Connectivity; | ||
import io.flutter.plugins.connectivity.ConnectivityBroadcastReceiver; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.RuntimeEnvironment; | ||
import org.robolectric.annotation.Config; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class ActivityTest { | ||
private ConnectivityManager connectivityManager; | ||
|
||
@Before | ||
public void setUp() { | ||
connectivityManager = | ||
(ConnectivityManager) | ||
RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
} | ||
|
||
@Test | ||
@Config(sdk = 24, manifest = Config.NONE) | ||
public void networkCallbackNewApi() { | ||
Context context = RuntimeEnvironment.application; | ||
Connectivity connectivity = spy(new Connectivity(connectivityManager)); | ||
ConnectivityBroadcastReceiver broadcastReceiver = | ||
spy(new ConnectivityBroadcastReceiver(context, connectivity)); | ||
|
||
broadcastReceiver.onListen(any(), any()); | ||
assertNotNull(broadcastReceiver.getNetworkCallback()); | ||
} | ||
|
||
@Test | ||
@Config(sdk = 23, manifest = Config.NONE) | ||
public void networkCallbackLowApi() { | ||
Context context = RuntimeEnvironment.application; | ||
Connectivity connectivity = spy(new Connectivity(connectivityManager)); | ||
ConnectivityBroadcastReceiver broadcastReceiver = | ||
spy(new ConnectivityBroadcastReceiver(context, connectivity)); | ||
|
||
broadcastReceiver.onListen(any(), any()); | ||
assertNull(broadcastReceiver.getNetworkCallback()); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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