From 5c7f29e8e37970c16ce5142b6deb9ef5f52af44a Mon Sep 17 00:00:00 2001 From: isuPatches Date: Sun, 23 Jul 2017 22:10:26 -0500 Subject: [PATCH] Move all tests to AndroidJUnit4 tests --- gradle/jacoco.gradle | 6 +- .../wisefy/AddOpenNetworkTests.java | 316 ++- .../isupatches/wisefy/AddWEPNetworkTests.java | 370 ++-- .../wisefy/AddWPA2NetworkTests.java | 368 ++-- ...s.java => BaseAndroidJUnit4TestClass.java} | 24 +- .../wisefy/ConnectToNetworkTests.java | 439 +++-- .../isupatches/wisefy/DisableWifiTests.java | 203 +- .../DisconnectFromCurrentNetworkTests.java | 201 +- .../isupatches/wisefy/EnableWifiTests.java | 203 +- .../wisefy/GetCurrentNetworkTests.java | 169 +- .../isupatches/wisefy/GetFrequencyTests.java | 311 ++- .../wisefy/GetNearbyAccessPointsTests.java | 415 ++-- .../com/isupatches/wisefy/GetRSSITests.java | 523 +++-- .../wisefy/GetSavedNetworkTests.java | 283 ++- .../wisefy/GetSavedNetworksTests.java | 481 +++-- ...IsDeviceConnectedToMobileNetworkTests.java | 87 +- ...ceConnectedToMobileOrWifiNetworkTests.java | 86 +- .../wisefy/IsDeviceConnectedToSSIDTests.java | 91 +- .../IsDeviceConnectedToWifiNetworkTests.java | 87 +- .../wisefy/IsDeviceRoamingTests.java | 79 +- .../isupatches/wisefy/IsNetwork5gHzTests.java | 199 +- .../isupatches/wisefy/IsNetworkEAPTests.java | 93 +- .../IsNetworkInConfigurationListTests.java | 193 +- .../isupatches/wisefy/IsNetworkPSKTest.java | 93 +- .../wisefy/IsNetworkSecureTests.java | 149 +- .../isupatches/wisefy/IsNetworkWPA2Test.java | 93 +- .../isupatches/wisefy/IsNetworkWPATests.java | 93 +- .../isupatches/wisefy/IsNetworkWepTests.java | 93 +- .../isupatches/wisefy/IsWifiEnabledTests.java | 61 +- .../isupatches/wisefy/ManagerUtilTest.java | 83 +- .../isupatches/wisefy/RemoveNetworkTests.java | 415 ++-- .../wisefy/SearchForAccessPointTests.java | 539 +++--- .../wisefy/SearchForAccessPointsTests.java | 568 +++--- .../isupatches/wisefy/SearchForSSIDTests.java | 293 ++- .../wisefy/SearchForSSIDsTests.java | 287 ++- .../wisefy/WiseFyConnectionTests.java | 723 ++++--- .../wisefy/WiseFyPrerequisitesTests.java | 103 +- .../isupatches/wisefy/WiseFySearchTests.java | 1716 ++++++++--------- .../com/isupatches/wisefy/WiseFyTests.java | 91 +- .../isupatches/wisefy/test/BuilderTests.java | 55 +- .../wisefy/test/PublicApiVisibilityTests.java | 15 +- 41 files changed, 5240 insertions(+), 5457 deletions(-) rename wisefy/src/androidTest/java/com/isupatches/wisefy/{BaseTestClass.java => BaseAndroidJUnit4TestClass.java} (74%) rename wisefy/src/{androidTest => test}/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java (97%) diff --git a/gradle/jacoco.gradle b/gradle/jacoco.gradle index 35661302..a35c74f5 100644 --- a/gradle/jacoco.gradle +++ b/gradle/jacoco.gradle @@ -17,13 +17,13 @@ def classDirs = fileTree( '**/*$Builder*']) task jacocoDebugTestReport(type: JacocoReport) { - dependsOn = ["connectedDebugAndroidTest"] + dependsOn = ["connectedDebugAndroidTest", "testDebugUnitTest"] group = "Reporting" description = "Run tests and generate Jacoco coverage report for debug" classDirectories = classDirs additionalSourceDirs = files(coverageSourceDirs) sourceDirectories = files(coverageSourceDirs) - executionData = files([fileTree(dir: 'build/outputs/code-coverage/connected', include: '**/*.ec')]) + executionData = files([fileTree(dir: 'build/outputs/code-coverage/connected', include: '**/*.ec'), fileTree(dir: 'build/jacoco', include: '**/*.exec')]) reports { xml.enabled = true @@ -37,7 +37,7 @@ task jacocoDebugReport(type: JacocoReport) { classDirectories = classDirs additionalSourceDirs = files(coverageSourceDirs) sourceDirectories = files(coverageSourceDirs) - executionData = files([fileTree(dir: 'build/outputs/code-coverage/connected', include: '**/*.ec')]) + executionData = files([fileTree(dir: 'build/outputs/code-coverage/connected', include: '**/*.ec'), fileTree(dir: 'build/jacoco', include: '**/*.exec')]) reports { xml.enabled = true diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.java index 8443d1d3..e020d4b3 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddOpenNetworkTests.java @@ -1,160 +1,156 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.callbacks.AddOpenNetworkCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.OPEN_NETWORK_SSID; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.assertNotEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class AddOpenNetworkTests extends BaseTestClass { -// -// public AddOpenNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_failure_nullSSIDParam() { -// assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addOpenNetwork(null)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_success() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_success_alreadyConfigured() { -// networkAlreadyInConfigurationList(); -// assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); -// mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingOpenNetwork(WiseFy.WIFI_MANAGER_FAILURE); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// try { -// mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam() { -// AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); -// mWiseFy.addOpenNetwork(null, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.addOpenNetwork(null, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); -// mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); -// mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).openNetworkAdded(any(WifiConfiguration.class)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// try { -// mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_alreadyConfigured() { -// networkAlreadyInConfigurationList(); -// -// AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); -// mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_success_alreadyConfigured_nullCallback() { -// networkAlreadyInConfigurationList(); -// -// try { -// mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} \ No newline at end of file +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.callbacks.AddOpenNetworkCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Assert; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.OPEN_NETWORK_SSID; +import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.*; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class AddOpenNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_failure_nullSSIDParam() { + Assert.assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addOpenNetwork(null)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_success() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_success_alreadyConfigured() { + networkAlreadyInConfigurationList(); + assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); + mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingOpenNetwork(WiseFy.WIFI_MANAGER_FAILURE); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_nullCallback() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + try { + mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_nullSSIDParam() { + AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); + mWiseFy.addOpenNetwork(null, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.addOpenNetwork(null, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); + mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); + mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).openNetworkAdded(any(WifiConfiguration.class)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_success_nullCallback() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + try { + mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_alreadyConfigured() { + networkAlreadyInConfigurationList(); + + AddOpenNetworkCallbacks mockCallbacks = mock(AddOpenNetworkCallbacks.class); + mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addOpenNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_success_alreadyConfigured_nullCallback() { + networkAlreadyInConfigurationList(); + + try { + mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } +} \ No newline at end of file diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.java index d8da7f89..9e672ec7 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWEPNetworkTests.java @@ -1,188 +1,182 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.AddWEPNetworkCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.WEP_NETWORK_PASSWORD; -//import static com.isupatches.wisefy.base.TestUtils.WEP_NETWORK_SSID; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.assertNotEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class AddWEPNetworkTests extends BaseTestClass { -// -// public AddWEPNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_failure_nullPasswordParam() { -// assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, null)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_failure_nullSSIDParam() { -// assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWEPNetwork(null, WEP_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_success() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_success_alreadyConfigured() { -// networkAlreadyInConfigurationList(); -// assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingWEPNetwork(WiseFy.WIFI_MANAGER_FAILURE); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// -// try { -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_nullPasswordParam() { -// AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, null, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_nullPasswordParam_nullCallback() { -// try { -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, null, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam() { -// AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); -// mWiseFy.addWEPNetwork(null, WEP_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.addWEPNetwork(null, WEP_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// -// try { -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wepNetworkAdded(any(WifiConfiguration.class)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// -// try { -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_alreadyConfigured() { -// networkAlreadyInConfigurationList(); -// -// AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_success_alreadyConfigured_nullCallback() { -// networkAlreadyInConfigurationList(); -// -// try { -// mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.base.TestUtils; +import com.isupatches.wisefy.callbacks.AddWEPNetworkCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class AddWEPNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_failure_nullPasswordParam() { + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, null)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_failure_nullSSIDParam() { + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWEPNetwork(null, TestUtils.WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_success() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_success_alreadyConfigured() { + networkAlreadyInConfigurationList(); + assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingWEPNetwork(WiseFy.WIFI_MANAGER_FAILURE); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_nullCallback() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + + try { + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_nullPasswordParam() { + AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, null, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_nullPasswordParam_nullCallback() { + try { + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, null, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_nullSSIDParam() { + AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); + mWiseFy.addWEPNetwork(null, TestUtils.WEP_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.addWEPNetwork(null, TestUtils.WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + + try { + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wepNetworkAdded(any(WifiConfiguration.class)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_success_nullCallback() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + + try { + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_alreadyConfigured() { + networkAlreadyInConfigurationList(); + + AddWEPNetworkCallbacks mockCallbacks = mock(AddWEPNetworkCallbacks.class); + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWEPNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_success_alreadyConfigured_nullCallback() { + networkAlreadyInConfigurationList(); + + try { + mWiseFy.addWEPNetwork(TestUtils.WEP_NETWORK_SSID, TestUtils.WEP_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.java index fab3629a..684e00c7 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/AddWPA2NetworkTests.java @@ -1,187 +1,181 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.AddWPA2NetworkCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.WPA2_NETWORK_PASSWORD; -//import static com.isupatches.wisefy.base.TestUtils.WPA2_NETWORK_SSID; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.assertNotEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class AddWPA2NetworkTests extends BaseTestClass { -// -// public AddWPA2NetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_failure_nullPasswordParam() { -// assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, null)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void anoCallbacks_failure_nullSSIDParam() { -// assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWPA2Network(null, WPA2_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_success() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void noCallbacks_success_alreadyConfigured() { -// networkAlreadyInConfigurationList(); -// assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD)); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingWPA2Network(WiseFy.WIFI_MANAGER_FAILURE); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); -// try { -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_nullPasswordParam() { -// AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, null, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_nullPasswordParam_nullCallback() { -// try { -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, null, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam() { -// AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); -// mWiseFy.addWPA2Network(null, WPA2_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, never()).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.addWPA2Network(null, WPA2_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// -// AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// -// try { -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wpa2NetworkAdded(any(WifiConfiguration.class)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); -// -// try { -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_alreadyConfigured() { -// networkAlreadyInConfigurationList(); -// -// AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } -// -// @Test -// public void callbacks_success_alreadyConfigured_nullCallback() { -// networkAlreadyInConfigurationList(); -// -// try { -// mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, null); -// verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.base.TestUtils; +import com.isupatches.wisefy.callbacks.AddWPA2NetworkCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class AddWPA2NetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + assertEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_failure_nullPasswordParam() { + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, null)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void anoCallbacks_failure_nullSSIDParam() { + assertEquals(WiseFyCodes.MISSING_PARAMETER, mWiseFy.addWPA2Network(null, TestUtils.WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(WiseFyCodes.MISSING_PREREQUISITE, mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_success() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void noCallbacks_success_alreadyConfigured() { + networkAlreadyInConfigurationList(); + assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD)); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureAddingWPA2Network(WiseFy.WIFI_MANAGER_FAILURE); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_nullCallback() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE); + try { + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_nullPasswordParam() { + AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, null, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_nullPasswordParam_nullCallback() { + try { + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, null, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_nullSSIDParam() { + AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); + mWiseFy.addWPA2Network(null, TestUtils.WPA2_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, never()).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.addWPA2Network(null, TestUtils.WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + + AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + + try { + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wpa2NetworkAdded(any(WifiConfiguration.class)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_success_nullCallback() { + when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0); + + try { + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_alreadyConfigured() { + networkAlreadyInConfigurationList(); + + AddWPA2NetworkCallbacks mockCallbacks = mock(AddWPA2NetworkCallbacks.class); + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).addWPA2NetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } + + @Test + public void callbacks_success_alreadyConfigured_nullCallback() { + networkAlreadyInConfigurationList(); + + try { + mWiseFy.addWPA2Network(TestUtils.WPA2_NETWORK_SSID, TestUtils.WPA2_NETWORK_PASSWORD, null); + verify(mMockWiFiManager, never()).addNetwork(any(WifiConfiguration.class)); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/BaseTestClass.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/BaseAndroidJUnit4TestClass.java similarity index 74% rename from wisefy/src/androidTest/java/com/isupatches/wisefy/BaseTestClass.java rename to wisefy/src/androidTest/java/com/isupatches/wisefy/BaseAndroidJUnit4TestClass.java index 070ec0d0..fbbc1f05 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/BaseTestClass.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/BaseAndroidJUnit4TestClass.java @@ -1,24 +1,20 @@ package com.isupatches.wisefy; -import android.app.Activity; -import android.content.Intent; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; -import android.support.test.rule.ActivityTestRule; -import com.isupatches.wisefy.base.TestActivity; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; -import org.junit.Rule; +import org.junit.runner.RunWith; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public abstract class BaseTestClass extends ActivityTestRule { - - @Rule - public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(TestActivity.class); +@RunWith(AndroidJUnit4.class) +public abstract class BaseAndroidJUnit4TestClass { ConnectivityManager mMockConnectivityManager; @@ -28,10 +24,6 @@ public abstract class BaseTestClass extends ActivityTestRule protected static final Integer VERIFICATION_TIMEOUT = 2000; - public BaseTestClass(Class activityClass) { - super(activityClass); - } - @Before public void setUp() { mMockWiFiManager = mock(WifiManager.class); @@ -40,9 +32,7 @@ public void setUp() { mMockWiFiManager = mock(WifiManager.class); mMockConnectivityManager = mock(ConnectivityManager.class); - mActivityTestRule.launchActivity(new Intent()); - - mWiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(true).getSmarts(); + mWiseFy = new WiseFy.brains(InstrumentationRegistry.getContext()).logging(true).getSmarts(); setManagers(); } @@ -75,4 +65,4 @@ private void setManagers() { when(mockPrereqs.getWifiManager()).thenReturn(mMockWiFiManager); when(mockPrereqs.getConnectivityManager()).thenReturn(mMockConnectivityManager); } -} \ No newline at end of file +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.java index 55e6e960..57bbcfe7 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/ConnectToNetworkTests.java @@ -1,222 +1,217 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.ConnectToNetworkCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.ArgumentMatchers.anyBoolean; -//import static org.mockito.ArgumentMatchers.anyInt; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class ConnectToNetworkTests extends BaseTestClass { -// -// public ConnectToNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_nullSSIDParam() { -// assertEquals(false, mWiseFy.connectToNetwork(null, 1)); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisites() { -// missingPrerequisite(); -// assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void noCallbacks_failure_noSavedNetwork() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void noCallbacks_failure() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(false); -// -// assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void noCallbacks_success() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(true); -// -// assertEquals(true, mWiseFy.connectToNetwork(TEST_SSID, 1)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam() { -// ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); -// mWiseFy.connectToNetwork(null, 1, mockCallbacks); -// verify(mockCallbacks, timeout(3000)).connectToNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.connectToNetwork(null, 1, null); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisites() { -// missingPrerequisite(); -// ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); -// mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); -// verify(mockCallbacks, timeout(3000)).connectToNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisites_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.connectToNetwork(TEST_SSID, 1, null); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_noSavedNetwork() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); -// mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkNotFoundToConnectTo(); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void callbacks_failure_noSavedNetwork_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// try { -// mWiseFy.connectToNetwork(TEST_SSID, 1, null); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(false); -// -// ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); -// mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureConnectingToNetwork(); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(false); -// -// try { -// mWiseFy.connectToNetwork(TEST_SSID, 1, null); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(true); -// -// ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); -// mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).connectedToNetwork(); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(true); -// -// try { -// mWiseFy.connectToNetwork(TEST_SSID, 1, null); -// verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} \ No newline at end of file +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.callbacks.ConnectToNetworkCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class ConnectToNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_nullSSIDParam() { + assertEquals(false, mWiseFy.connectToNetwork(null, 1)); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void noCallbacks_failure_missingPrerequisites() { + missingPrerequisite(); + assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void noCallbacks_failure_noSavedNetwork() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void noCallbacks_failure() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(false); + + assertEquals(false, mWiseFy.connectToNetwork(TEST_SSID, 1)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void noCallbacks_success() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(true); + + assertEquals(true, mWiseFy.connectToNetwork(TEST_SSID, 1)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void callbacks_failure_nullSSIDParam() { + ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); + mWiseFy.connectToNetwork(null, 1, mockCallbacks); + verify(mockCallbacks, timeout(3000)).connectToNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.connectToNetwork(null, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisites() { + missingPrerequisite(); + ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); + mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); + verify(mockCallbacks, timeout(3000)).connectToNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void callbacks_failure_missingPrerequisites_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.connectToNetwork(TEST_SSID, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_noSavedNetwork() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); + mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkNotFoundToConnectTo(); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void callbacks_failure_noSavedNetwork_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + try { + mWiseFy.connectToNetwork(TEST_SSID, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(false); + + ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); + mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureConnectingToNetwork(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void callbacks_failure_nullCallback() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(false); + + try { + mWiseFy.connectToNetwork(TEST_SSID, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(true); + + ConnectToNetworkCallbacks mockCallbacks = mock(ConnectToNetworkCallbacks.class); + mWiseFy.connectToNetwork(TEST_SSID, 1, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).connectedToNetwork(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).enableNetwork(anyInt(), anyBoolean()); + } + + @Test + public void callbacks_success_nullCallback() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.waitToConnectToSSID(anyString(), anyInt())).thenReturn(true); + + try { + mWiseFy.connectToNetwork(TEST_SSID, 1, null); + verify(mMockWiFiManager, never()).enableNetwork(anyInt(), anyBoolean()); + } catch (NullPointerException npe) { + fail(); + } + } +} \ No newline at end of file diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.java index f77d387a..10552123 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisableWifiTests.java @@ -1,104 +1,99 @@ -//package com.isupatches.wisefy; -// -// -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.DisableWifiCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.ArgumentMatchers.anyBoolean; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class DisableWifiTests extends BaseTestClass { -// -// public DisableWifiTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); -// assertEquals(false, mWiseFy.disableWifi()); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(false, mWiseFy.disableWifi()); -// verify(mMockWiFiManager, never()).setWifiEnabled(false); -// } -// -// @Test -// public void noCallbacks_success() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); -// assertEquals(true, mWiseFy.disableWifi()); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); -// } -// -// @Test -// public void callbacks_failure() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); -// DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); -// mWiseFy.disableWifi(mockCallbacks); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureDisablingWifi(); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); -// try { -// mWiseFy.disableWifi(null); -// verify(mMockWiFiManager, never()).setWifiEnabled(false); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); -// mWiseFy.disableWifi(mockCallbacks); -// verify(mMockWiFiManager, never()).setWifiEnabled(false); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disableWifiWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.disableWifi(null); -// verify(mMockWiFiManager, never()).setWifiEnabled(false); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); -// DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); -// mWiseFy.disableWifi(mockCallbacks); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wifiDisabled(); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); -// try { -// mWiseFy.disableWifi(null); -// verify(mMockWiFiManager, never()).setWifiEnabled(false); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import com.isupatches.wisefy.callbacks.DisableWifiCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class DisableWifiTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); + assertEquals(false, mWiseFy.disableWifi()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(false, mWiseFy.disableWifi()); + verify(mMockWiFiManager, never()).setWifiEnabled(false); + } + + @Test + public void noCallbacks_success() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); + assertEquals(true, mWiseFy.disableWifi()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); + } + + @Test + public void callbacks_failure() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); + DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); + mWiseFy.disableWifi(mockCallbacks); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureDisablingWifi(); + } + + @Test + public void callbacks_failure_nullCallback() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); + try { + mWiseFy.disableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(false); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); + mWiseFy.disableWifi(mockCallbacks); + verify(mMockWiFiManager, never()).setWifiEnabled(false); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disableWifiWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.disableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(false); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); + DisableWifiCallbacks mockCallbacks = mock(DisableWifiCallbacks.class); + mWiseFy.disableWifi(mockCallbacks); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(false); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wifiDisabled(); + } + + @Test + public void callbacks_success_nullCallback() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); + try { + mWiseFy.disableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(false); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.java index 9b10a2eb..979e6311 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/DisconnectFromCurrentNetworkTests.java @@ -1,103 +1,98 @@ -//package com.isupatches.wisefy; -// -// -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.DisconnectFromCurrentNetworkCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class DisconnectFromCurrentNetworkTests extends BaseTestClass { -// -// public DisconnectFromCurrentNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure() { -// when(mMockWiFiManager.disconnect()).thenReturn(false); -// assertEquals(false, mWiseFy.disconnectFromCurrentNetwork()); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(false, mWiseFy.disconnectFromCurrentNetwork()); -// verify(mMockWiFiManager, never()).disconnect(); -// } -// -// @Test -// public void noCallbacks_success() { -// when(mMockWiFiManager.disconnect()).thenReturn(true); -// assertEquals(true, mWiseFy.disconnectFromCurrentNetwork()); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); -// } -// -// @Test -// public void callbacks_failure() { -// when(mMockWiFiManager.disconnect()).thenReturn(false); -// DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); -// mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureDisconnectingFromCurrentNetwork(); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// when(mMockWiFiManager.disconnect()).thenReturn(false); -// try { -// mWiseFy.disconnectFromCurrentNetwork(null); -// verify(mMockWiFiManager, never()).disconnect(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); -// mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); -// verify(mMockWiFiManager, never()).disconnect(); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disconnectFromCurrentNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.disconnectFromCurrentNetwork(null); -// verify(mMockWiFiManager, never()).disconnect(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// when(mMockWiFiManager.disconnect()).thenReturn(true); -// DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); -// mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disconnectedFromCurrentNetwork(); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// when(mMockWiFiManager.disconnect()).thenReturn(true); -// try { -// mWiseFy.disconnectFromCurrentNetwork(null); -// verify(mMockWiFiManager, never()).disconnect(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import com.isupatches.wisefy.callbacks.DisconnectFromCurrentNetworkCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class DisconnectFromCurrentNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure() { + when(mMockWiFiManager.disconnect()).thenReturn(false); + assertEquals(false, mWiseFy.disconnectFromCurrentNetwork()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(false, mWiseFy.disconnectFromCurrentNetwork()); + verify(mMockWiFiManager, never()).disconnect(); + } + + @Test + public void noCallbacks_success() { + when(mMockWiFiManager.disconnect()).thenReturn(true); + assertEquals(true, mWiseFy.disconnectFromCurrentNetwork()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); + } + + @Test + public void callbacks_failure() { + when(mMockWiFiManager.disconnect()).thenReturn(false); + DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); + mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureDisconnectingFromCurrentNetwork(); + } + + @Test + public void callbacks_failure_nullCallback() { + when(mMockWiFiManager.disconnect()).thenReturn(false); + try { + mWiseFy.disconnectFromCurrentNetwork(null); + verify(mMockWiFiManager, never()).disconnect(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); + mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); + verify(mMockWiFiManager, never()).disconnect(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disconnectFromCurrentNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.disconnectFromCurrentNetwork(null); + verify(mMockWiFiManager, never()).disconnect(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + when(mMockWiFiManager.disconnect()).thenReturn(true); + DisconnectFromCurrentNetworkCallbacks mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks.class); + mWiseFy.disconnectFromCurrentNetwork(mockCallbacks); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).disconnect(); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).disconnectedFromCurrentNetwork(); + } + + @Test + public void callbacks_success_nullCallback() { + when(mMockWiFiManager.disconnect()).thenReturn(true); + try { + mWiseFy.disconnectFromCurrentNetwork(null); + verify(mMockWiFiManager, never()).disconnect(); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.java index e68d4e38..30eb1b63 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/EnableWifiTests.java @@ -1,104 +1,99 @@ -//package com.isupatches.wisefy; -// -// -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.EnableWifiCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.ArgumentMatchers.anyBoolean; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class EnableWifiTests extends BaseTestClass { -// -// public EnableWifiTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); -// assertEquals(false, mWiseFy.enableWifi()); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(false, mWiseFy.enableWifi()); -// verify(mMockWiFiManager, never()).setWifiEnabled(true); -// } -// -// @Test -// public void noCallbacks_success() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); -// assertEquals(true, mWiseFy.enableWifi()); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); -// } -// -// @Test -// public void callbacks_failure() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); -// EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); -// mWiseFy.enableWifi(mockCallbacks); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureEnablingWifi(); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); -// try { -// mWiseFy.enableWifi(null); -// verify(mMockWiFiManager, never()).setWifiEnabled(true); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); -// mWiseFy.enableWifi(mockCallbacks); -// verify(mMockWiFiManager, never()).setWifiEnabled(true); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).enableWifiWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.enableWifi(null); -// verify(mMockWiFiManager, never()).setWifiEnabled(true); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); -// EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); -// mWiseFy.enableWifi(mockCallbacks); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wifiEnabled(); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); -// try { -// mWiseFy.enableWifi(null); -// verify(mMockWiFiManager, never()).setWifiEnabled(true); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import com.isupatches.wisefy.callbacks.EnableWifiCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class EnableWifiTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); + assertEquals(false, mWiseFy.enableWifi()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(false, mWiseFy.enableWifi()); + verify(mMockWiFiManager, never()).setWifiEnabled(true); + } + + @Test + public void noCallbacks_success() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); + assertEquals(true, mWiseFy.enableWifi()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); + } + + @Test + public void callbacks_failure() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); + EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); + mWiseFy.enableWifi(mockCallbacks); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureEnablingWifi(); + } + + @Test + public void callbacks_failure_nullCallback() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(false); + try { + mWiseFy.enableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(true); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); + mWiseFy.enableWifi(mockCallbacks); + verify(mMockWiFiManager, never()).setWifiEnabled(true); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).enableWifiWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.enableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(true); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); + EnableWifiCallbacks mockCallbacks = mock(EnableWifiCallbacks.class); + mWiseFy.enableWifi(mockCallbacks); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).setWifiEnabled(true); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).wifiEnabled(); + } + + @Test + public void callbacks_success_nullCallback() { + when(mMockWiFiManager.setWifiEnabled(anyBoolean())).thenReturn(true); + try { + mWiseFy.enableWifi(null); + verify(mMockWiFiManager, never()).setWifiEnabled(true); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.java index 960f7bbc..7f10e2c6 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetCurrentNetworkTests.java @@ -1,87 +1,82 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiInfo; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.assertEquals; -//import static junit.framework.Assert.fail; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class GetCurrentNetworkTests extends BaseTestClass { -// -// public GetCurrentNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.getCurrentNetwork()); -// verify(mMockWiFiManager, never()).getConnectionInfo(); -// } -// -// @Test -// public void noCallbacks_success() { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(TEST_SSID, mWiseFy.getCurrentNetwork().getSSID()); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConnectionInfo(); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// GetCurrentNetworkCallbacks mockCallbacks = mock(GetCurrentNetworkCallbacks.class); -// mWiseFy.getCurrentNetwork(mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getCurrentNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).getConnectionInfo(); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallbacks() { -// missingPrerequisite(); -// try { -// mWiseFy.getCurrentNetwork(null); -// verify(mMockWiFiManager, never()).getConnectionInfo(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// GetCurrentNetworkCallbacks mockCallbacks = mock(GetCurrentNetworkCallbacks.class); -// mWiseFy.getCurrentNetwork(mockCallbacks); -// verify(mockCallbacks, timeout(2000)).retrievedCurrentNetwork(mockWifiInfo); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConnectionInfo(); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// try { -// mWiseFy.getCurrentNetwork(null); -// verify(mMockWiFiManager, never()).getConnectionInfo(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiInfo; +import com.isupatches.wisefy.callbacks.GetCurrentNetworkCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class GetCurrentNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getCurrentNetwork()); + verify(mMockWiFiManager, never()).getConnectionInfo(); + } + + @Test + public void noCallbacks_success() { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(TEST_SSID, mWiseFy.getCurrentNetwork().getSSID()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConnectionInfo(); + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + GetCurrentNetworkCallbacks mockCallbacks = mock(GetCurrentNetworkCallbacks.class); + mWiseFy.getCurrentNetwork(mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getCurrentNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getConnectionInfo(); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallbacks() { + missingPrerequisite(); + try { + mWiseFy.getCurrentNetwork(null); + verify(mMockWiFiManager, never()).getConnectionInfo(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + GetCurrentNetworkCallbacks mockCallbacks = mock(GetCurrentNetworkCallbacks.class); + mWiseFy.getCurrentNetwork(mockCallbacks); + verify(mockCallbacks, timeout(2000)).retrievedCurrentNetwork(mockWifiInfo); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConnectionInfo(); + } + + @Test + public void callbacks_success_nullCallback() { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + try { + mWiseFy.getCurrentNetwork(null); + verify(mMockWiFiManager, never()).getConnectionInfo(); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.java index 181af04e..d5f7542d 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetFrequencyTests.java @@ -1,158 +1,153 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiInfo; -//import android.os.Build; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_24GHZ; -//import static junit.framework.Assert.assertEquals; -//import static junit.framework.Assert.fail; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class GetFrequencyTests extends BaseTestClass { -// -// public GetFrequencyTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_getFrequency_currentNetwork_failure() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// assertEquals(null, mWiseFy.getFrequency()); -// } -// } -// -// @Test -// public void noCallbacks_getFrequency_currentNetwork_success() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// assertEquals(TEST_NETWORK_FREQUENCY_24GHZ, (int) mWiseFy.getFrequency()); -// verify(mockWifiInfo, timeout(VERIFICATION_TIMEOUT)).getFrequency(); -// } -// } -// -// @Test -// public void callbacks_getFrequency_currentNetwork_failure() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); -// mWiseFy.getFrequency(mockCallbacks); -// verify(mockCallbacks, timeout(2000)).failureGettingFrequency(); -// } -// } -// -// @Test -// public void callbacks_getFrequency_currentNetwork_failure_nullCallback() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// try { -// mWiseFy.getFrequency((GetFrequencyCallbacks) null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// } -// -// @Test -// public void callbacks_getFrequency_currentNetwork_success() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); -// mWiseFy.getFrequency(mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedFrequency(TEST_NETWORK_FREQUENCY_24GHZ); -// verify(mockWifiInfo, timeout(VERIFICATION_TIMEOUT)).getFrequency(); -// } -// } -// -// @Test -// public void callbacks_getFrequency_currentNetwork_success_nullCallback() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// try { -// mWiseFy.getFrequency((GetFrequencyCallbacks) null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// } -// -// @Test -// public void noCallbacks_getFrequency_provideWifiInfo_failure() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// assertEquals(null, mWiseFy.getFrequency((WifiInfo) null)); -// } -// } -// -// @Test -// public void noCallbacks_getFrequency_provideWifiInfo_success() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// assertEquals(TEST_NETWORK_FREQUENCY_24GHZ, (int) mWiseFy.getFrequency(mockWifiInfo)); -// } -// } -// -// @Test -// public void callbacks_getFrequency_provideWifiInfo_failure() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); -// mWiseFy.getFrequency(null, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).getFrequencyWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// } -// -// @Test -// public void callbacks_getFrequency_provideWifiInfo_failure_nullCallback() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// try { -// mWiseFy.getFrequency(null, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// } -// -// @Test -// public void callbacks_getFrequency_provideWifiInfo_success() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); -// mWiseFy.getFrequency(mockWifiInfo, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).retrievedFrequency(TEST_NETWORK_FREQUENCY_24GHZ); -// } -// } -// -// @Test -// public void callbacks_getFrequency_provideWifiInfo_success_nullCallback() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// try { -// mWiseFy.getFrequency(mockWifiInfo, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiInfo; +import android.os.Build; +import com.isupatches.wisefy.callbacks.GetFrequencyCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_24GHZ; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class GetFrequencyTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_getFrequency_currentNetwork_failure() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + assertEquals(null, mWiseFy.getFrequency()); + } + } + + @Test + public void noCallbacks_getFrequency_currentNetwork_success() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + assertEquals(TEST_NETWORK_FREQUENCY_24GHZ, (int) mWiseFy.getFrequency()); + verify(mockWifiInfo, timeout(VERIFICATION_TIMEOUT)).getFrequency(); + } + } + + @Test + public void callbacks_getFrequency_currentNetwork_failure() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); + mWiseFy.getFrequency(mockCallbacks); + verify(mockCallbacks, timeout(2000)).failureGettingFrequency(); + } + } + + @Test + public void callbacks_getFrequency_currentNetwork_failure_nullCallback() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + try { + mWiseFy.getFrequency((GetFrequencyCallbacks) null); + } catch (NullPointerException npe) { + fail(); + } + } + } + + @Test + public void callbacks_getFrequency_currentNetwork_success() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); + mWiseFy.getFrequency(mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedFrequency(TEST_NETWORK_FREQUENCY_24GHZ); + verify(mockWifiInfo, timeout(VERIFICATION_TIMEOUT)).getFrequency(); + } + } + + @Test + public void callbacks_getFrequency_currentNetwork_success_nullCallback() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + try { + mWiseFy.getFrequency((GetFrequencyCallbacks) null); + } catch (NullPointerException npe) { + fail(); + } + } + } + + @Test + public void noCallbacks_getFrequency_provideWifiInfo_failure() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + assertEquals(null, mWiseFy.getFrequency((WifiInfo) null)); + } + } + + @Test + public void noCallbacks_getFrequency_provideWifiInfo_success() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + assertEquals(TEST_NETWORK_FREQUENCY_24GHZ, (int) mWiseFy.getFrequency(mockWifiInfo)); + } + } + + @Test + public void callbacks_getFrequency_provideWifiInfo_failure() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); + mWiseFy.getFrequency(null, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getFrequencyWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + } + + @Test + public void callbacks_getFrequency_provideWifiInfo_failure_nullCallback() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + try { + mWiseFy.getFrequency(null, null); + } catch (NullPointerException npe) { + fail(); + } + } + } + + @Test + public void callbacks_getFrequency_provideWifiInfo_success() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + GetFrequencyCallbacks mockCallbacks = mock(GetFrequencyCallbacks.class); + mWiseFy.getFrequency(mockWifiInfo, mockCallbacks); + verify(mockCallbacks, timeout(2000)).retrievedFrequency(TEST_NETWORK_FREQUENCY_24GHZ); + } + } + + @Test + public void callbacks_getFrequency_provideWifiInfo_success_nullCallback() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + try { + mWiseFy.getFrequency(mockWifiInfo, null); + } catch (NullPointerException npe) { + fail(); + } + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.java index c8c64b5e..e9144cac 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetNearbyAccessPointsTests.java @@ -1,210 +1,205 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import org.mockito.ArgumentMatchers; -//import java.util.ArrayList; -//import java.util.List; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; -//import static junit.framework.Assert.assertEquals; -//import static junit.framework.Assert.fail; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class GetNearbyAccessPointsTests extends BaseTestClass { -// -// public GetNearbyAccessPointsTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite_filterDuplicates_false() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.getNearbyAccessPoints(false)); -// verify(mMockWiFiManager, never()).getScanResults(); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite_filterDuplicates_true() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.getNearbyAccessPoints(true)); -// verify(mMockWiFiManager, never()).getScanResults(); -// } -// -// @Test -// public void noCallbacks_success_filterDuplicates_false() { -// List scanResults = new ArrayList<>(); -// ScanResult scanResult1 = mock(ScanResult.class); -// scanResult1.SSID = TEST_SSID; -// scanResult1.level = -35; -// scanResults.add(scanResult1); -// ScanResult scanResult2 = mock(ScanResult.class); -// scanResult2.SSID = TEST_SSID2; -// scanResult2.level = -70; -// scanResults.add(scanResult2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); -// -// List accessPoints = mWiseFy.getNearbyAccessPoints(false); -// assertEquals(accessPoints, scanResults); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); -// } -// -// @Test -// public void noCallbacks_success_filterDuplicates_true() { -// List scanResults = new ArrayList<>(); -// ScanResult scanResult1 = mock(ScanResult.class); -// scanResult1.SSID = TEST_SSID; -// scanResult1.level = -35; -// scanResults.add(scanResult1); -// ScanResult scanResult2 = mock(ScanResult.class); -// scanResult2.SSID = TEST_SSID2; -// scanResult2.level = -70; -// scanResults.add(scanResult2); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.removeEntriesWithLowerSignalStrength(ArgumentMatchers.anyList())).thenReturn(scanResults); -// -// List accessPoints = mWiseFy.getNearbyAccessPoints(true); -// assertEquals(accessPoints, scanResults); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_filterDuplicates_false() { -// missingPrerequisite(); -// GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); -// mWiseFy.getNearbyAccessPoints(false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getNearbyAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).getScanResults(); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_filterDuplicates_false_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.getNearbyAccessPoints(false, null); -// verify(mMockWiFiManager, never()).getScanResults(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_filterDuplicates_true() { -// missingPrerequisite(); -// GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); -// mWiseFy.getNearbyAccessPoints(true, mockCallbacks); -// verify(mockCallbacks, timeout(3000)).getNearbyAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).getScanResults(); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_filterDuplicates_true_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.getNearbyAccessPoints(true, null); -// verify(mMockWiFiManager, never()).getScanResults(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_filterDuplicates_false() { -// List scanResults = new ArrayList<>(); -// ScanResult scanResult1 = mock(ScanResult.class); -// scanResult1.SSID = TEST_SSID; -// scanResult1.level = -35; -// scanResults.add(scanResult1); -// ScanResult scanResult2 = mock(ScanResult.class); -// scanResult2.SSID = TEST_SSID2; -// scanResult2.level = -70; -// scanResults.add(scanResult2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); -// -// GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); -// mWiseFy.getNearbyAccessPoints(false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedNearbyAccessPoints(scanResults); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); -// } -// -// @Test -// public void callbacks_success_filterDuplicates_false_nullCallback() { -// List scanResults = new ArrayList<>(); -// ScanResult scanResult1 = mock(ScanResult.class); -// scanResult1.SSID = TEST_SSID; -// scanResult1.level = -35; -// scanResults.add(scanResult1); -// ScanResult scanResult2 = mock(ScanResult.class); -// scanResult2.SSID = TEST_SSID2; -// scanResult2.level = -70; -// scanResults.add(scanResult2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); -// -// try { -// mWiseFy.getNearbyAccessPoints(false, null); -// verify(mMockWiFiManager, never()).getScanResults(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_filterDuplicates_true() { -// List scanResults = new ArrayList<>(); -// ScanResult scanResult1 = mock(ScanResult.class); -// scanResult1.SSID = TEST_SSID; -// scanResult1.level = -35; -// scanResults.add(scanResult1); -// ScanResult scanResult2 = mock(ScanResult.class); -// scanResult2.SSID = TEST_SSID2; -// scanResult2.level = -70; -// scanResults.add(scanResult2); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.removeEntriesWithLowerSignalStrength(ArgumentMatchers.anyList())).thenReturn(scanResults); -// -// GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); -// mWiseFy.getNearbyAccessPoints(true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedNearbyAccessPoints(scanResults); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); -// } -// -// @Test -// public void callbacks_success_filterDuplicates_true_nullCallback() { -// List scanResults = new ArrayList<>(); -// ScanResult scanResult1 = mock(ScanResult.class); -// scanResult1.SSID = TEST_SSID; -// scanResult1.level = -35; -// scanResults.add(scanResult1); -// ScanResult scanResult2 = mock(ScanResult.class); -// scanResult2.SSID = TEST_SSID2; -// scanResult2.level = -70; -// scanResults.add(scanResult2); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.removeEntriesWithLowerSignalStrength(ArgumentMatchers.anyList())).thenReturn(scanResults); -// -// try { -// mWiseFy.getNearbyAccessPoints(true, null); -// verify(mMockWiFiManager, never()).getScanResults(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} \ No newline at end of file +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.callbacks.GetNearbyAccessPointsCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import java.util.ArrayList; +import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class GetNearbyAccessPointsTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_missingPrerequisite_filterDuplicates_false() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getNearbyAccessPoints(false)); + verify(mMockWiFiManager, never()).getScanResults(); + } + + @Test + public void noCallbacks_failure_missingPrerequisite_filterDuplicates_true() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getNearbyAccessPoints(true)); + verify(mMockWiFiManager, never()).getScanResults(); + } + + @Test + public void noCallbacks_success_filterDuplicates_false() { + List scanResults = new ArrayList<>(); + ScanResult scanResult1 = mock(ScanResult.class); + scanResult1.SSID = TEST_SSID; + scanResult1.level = -35; + scanResults.add(scanResult1); + ScanResult scanResult2 = mock(ScanResult.class); + scanResult2.SSID = TEST_SSID2; + scanResult2.level = -70; + scanResults.add(scanResult2); + + when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); + + List accessPoints = mWiseFy.getNearbyAccessPoints(false); + assertEquals(accessPoints, scanResults); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); + } + + @Test + public void noCallbacks_success_filterDuplicates_true() { + List scanResults = new ArrayList<>(); + ScanResult scanResult1 = mock(ScanResult.class); + scanResult1.SSID = TEST_SSID; + scanResult1.level = -35; + scanResults.add(scanResult1); + ScanResult scanResult2 = mock(ScanResult.class); + scanResult2.SSID = TEST_SSID2; + scanResult2.level = -70; + scanResults.add(scanResult2); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.removeEntriesWithLowerSignalStrength(ArgumentMatchers.anyList())).thenReturn(scanResults); + + List accessPoints = mWiseFy.getNearbyAccessPoints(true); + assertEquals(accessPoints, scanResults); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); + } + + @Test + public void callbacks_failure_missingPrerequisite_filterDuplicates_false() { + missingPrerequisite(); + GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); + mWiseFy.getNearbyAccessPoints(false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getNearbyAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getScanResults(); + } + + @Test + public void callbacks_failure_missingPrerequisite_filterDuplicates_false_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.getNearbyAccessPoints(false, null); + verify(mMockWiFiManager, never()).getScanResults(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite_filterDuplicates_true() { + missingPrerequisite(); + GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); + mWiseFy.getNearbyAccessPoints(true, mockCallbacks); + verify(mockCallbacks, timeout(3000)).getNearbyAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getScanResults(); + } + + @Test + public void callbacks_failure_missingPrerequisite_filterDuplicates_true_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.getNearbyAccessPoints(true, null); + verify(mMockWiFiManager, never()).getScanResults(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_filterDuplicates_false() { + List scanResults = new ArrayList<>(); + ScanResult scanResult1 = mock(ScanResult.class); + scanResult1.SSID = TEST_SSID; + scanResult1.level = -35; + scanResults.add(scanResult1); + ScanResult scanResult2 = mock(ScanResult.class); + scanResult2.SSID = TEST_SSID2; + scanResult2.level = -70; + scanResults.add(scanResult2); + + when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); + + GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); + mWiseFy.getNearbyAccessPoints(false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedNearbyAccessPoints(scanResults); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); + } + + @Test + public void callbacks_success_filterDuplicates_false_nullCallback() { + List scanResults = new ArrayList<>(); + ScanResult scanResult1 = mock(ScanResult.class); + scanResult1.SSID = TEST_SSID; + scanResult1.level = -35; + scanResults.add(scanResult1); + ScanResult scanResult2 = mock(ScanResult.class); + scanResult2.SSID = TEST_SSID2; + scanResult2.level = -70; + scanResults.add(scanResult2); + + when(mMockWiFiManager.getScanResults()).thenReturn(scanResults); + + try { + mWiseFy.getNearbyAccessPoints(false, null); + verify(mMockWiFiManager, never()).getScanResults(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_filterDuplicates_true() { + List scanResults = new ArrayList<>(); + ScanResult scanResult1 = mock(ScanResult.class); + scanResult1.SSID = TEST_SSID; + scanResult1.level = -35; + scanResults.add(scanResult1); + ScanResult scanResult2 = mock(ScanResult.class); + scanResult2.SSID = TEST_SSID2; + scanResult2.level = -70; + scanResults.add(scanResult2); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.removeEntriesWithLowerSignalStrength(ArgumentMatchers.anyList())).thenReturn(scanResults); + + GetNearbyAccessPointsCallbacks mockCallbacks = mock(GetNearbyAccessPointsCallbacks.class); + mWiseFy.getNearbyAccessPoints(true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedNearbyAccessPoints(scanResults); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getScanResults(); + } + + @Test + public void callbacks_success_filterDuplicates_true_nullCallback() { + List scanResults = new ArrayList<>(); + ScanResult scanResult1 = mock(ScanResult.class); + scanResult1.SSID = TEST_SSID; + scanResult1.level = -35; + scanResults.add(scanResult1); + ScanResult scanResult2 = mock(ScanResult.class); + scanResult2.SSID = TEST_SSID2; + scanResult2.level = -70; + scanResults.add(scanResult2); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.removeEntriesWithLowerSignalStrength(ArgumentMatchers.anyList())).thenReturn(scanResults); + + try { + mWiseFy.getNearbyAccessPoints(true, null); + verify(mMockWiFiManager, never()).getScanResults(); + } catch (NullPointerException npe) { + fail(); + } + } +} \ No newline at end of file diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetRSSITests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetRSSITests.java index f6b6300c..1f622a6f 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetRSSITests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetRSSITests.java @@ -1,264 +1,259 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.GetRSSICallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_RSSI_LEVEL; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.assertEquals; -//import static junit.framework.Assert.fail; -//import static org.mockito.ArgumentMatchers.anyBoolean; -//import static org.mockito.ArgumentMatchers.anyInt; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class GetRSSITests extends BaseTestClass { -// -// public GetRSSITests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_takeHighest_false_nullSSIDParam() { -// assertEquals(null, mWiseFy.getRSSI(null, false, 1000)); -// } -// -// @Test -// public void noCallbacks_failure_takeHighest_true_nullSSIDParam() { -// assertEquals(null, mWiseFy.getRSSI(null, true, 1000)); -// } -// -// @Test -// public void noCallbacks_failure_takeHighest_false_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.getRSSI(TEST_SSID, false, 1000)); -// } -// -// @Test -// public void noCallbacks_failure_takeHighest_true_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.getRSSI(TEST_SSID, true, 1000)); -// } -// -// @Test -// public void noCallbacks_failure_takeHighest_false_noNetworkFound() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// assertEquals(null, mWiseFy.getRSSI(TEST_SSID, false, 1000)); -// } -// -// @Test -// public void noCallbacks_failure_takeHighest_true_noNetworkFound() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// assertEquals(null, mWiseFy.getRSSI(TEST_SSID, true, 1000)); -// } -// -// @Test -// public void noCallbacks_success_takeHighest_false () { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.level = TEST_RSSI_LEVEL; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// assertEquals(TEST_RSSI_LEVEL, (int) mWiseFy.getRSSI(TEST_SSID, false, 1000)); -// -// } -// -// @Test -// public void noCallbacks_success_takeHighest_true () { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.level = TEST_RSSI_LEVEL; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// assertEquals(TEST_RSSI_LEVEL, (int) mWiseFy.getRSSI(TEST_SSID, true, 1000)); -// } -// -// @Test -// public void callbacks_failure_takeHighest_false_nullSSIDParam() { -// GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); -// mWiseFy.getRSSI(null, false, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).getRSSIWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_takeHighest_false_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.getRSSI(null, false, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_takeHighest_true_nullSSIDParam() { -// GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); -// mWiseFy.getRSSI(null, true, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).getRSSIWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_takeHighest_true_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.getRSSI(null, true, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_takeHighest_false_missingPrerequisite() { -// missingPrerequisite(); -// GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); -// mWiseFy.getRSSI(TEST_SSID, false, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).getRSSIWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_takeHighest_false_nullSSIDParam_missingPrerequisite() { -// missingPrerequisite(); -// try { -// mWiseFy.getRSSI(TEST_SSID, false, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_takeHighest_true_missingPrerequisite() { -// missingPrerequisite(); -// GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); -// mWiseFy.getRSSI(TEST_SSID, true, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).getRSSIWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_takeHighest_true_nullSSIDParam_missingPrerequisite() { -// missingPrerequisite(); -// try { -// mWiseFy.getRSSI(TEST_SSID, true, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_takeHighest_false_noNetworkFound() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); -// mWiseFy.getRSSI(TEST_SSID, false, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).networkNotFoundToRetrieveRSSI(); -// } -// -// @Test -// public void callbacks_failure_takeHighest_false_noNetworkFound_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// try { -// mWiseFy.getRSSI(TEST_SSID, false, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_takeHighest_true_noNetworkFound() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); -// mWiseFy.getRSSI(TEST_SSID, true, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).networkNotFoundToRetrieveRSSI(); -// } -// -// @Test -// public void callbacks_failure_takeHighest_true_noNetworkFound_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// try { -// mWiseFy.getRSSI(TEST_SSID, true, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_takeHighest_false() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.level = TEST_RSSI_LEVEL; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// -// GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); -// mWiseFy.getRSSI(TEST_SSID, false, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).retrievedRSSI(TEST_RSSI_LEVEL); -// } -// -// @Test -// public void callbacks_success_takeHighest_false_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.level = TEST_RSSI_LEVEL; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// try { -// mWiseFy.getRSSI(TEST_SSID, false, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_takeHighest_true() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.level = TEST_RSSI_LEVEL; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// -// GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); -// mWiseFy.getRSSI(TEST_SSID, true, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).retrievedRSSI(TEST_RSSI_LEVEL); -// } -// -// @Test -// public void callbacks_success_takeHighest_true_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.level = TEST_RSSI_LEVEL; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// try { -// mWiseFy.getRSSI(TEST_SSID, true, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} \ No newline at end of file +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.callbacks.GetRSSICallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_RSSI_LEVEL; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class GetRSSITests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_takeHighest_false_nullSSIDParam() { + assertEquals(null, mWiseFy.getRSSI(null, false, 1000)); + } + + @Test + public void noCallbacks_failure_takeHighest_true_nullSSIDParam() { + assertEquals(null, mWiseFy.getRSSI(null, true, 1000)); + } + + @Test + public void noCallbacks_failure_takeHighest_false_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getRSSI(TEST_SSID, false, 1000)); + } + + @Test + public void noCallbacks_failure_takeHighest_true_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getRSSI(TEST_SSID, true, 1000)); + } + + @Test + public void noCallbacks_failure_takeHighest_false_noNetworkFound() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + assertEquals(null, mWiseFy.getRSSI(TEST_SSID, false, 1000)); + } + + @Test + public void noCallbacks_failure_takeHighest_true_noNetworkFound() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + assertEquals(null, mWiseFy.getRSSI(TEST_SSID, true, 1000)); + } + + @Test + public void noCallbacks_success_takeHighest_false () { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.level = TEST_RSSI_LEVEL; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + assertEquals(TEST_RSSI_LEVEL, (int) mWiseFy.getRSSI(TEST_SSID, false, 1000)); + + } + + @Test + public void noCallbacks_success_takeHighest_true () { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.level = TEST_RSSI_LEVEL; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + assertEquals(TEST_RSSI_LEVEL, (int) mWiseFy.getRSSI(TEST_SSID, true, 1000)); + } + + @Test + public void callbacks_failure_takeHighest_false_nullSSIDParam() { + GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); + mWiseFy.getRSSI(null, false, 1000, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getRSSIWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_takeHighest_false_nullSSIDParam_nullCallback() { + try { + mWiseFy.getRSSI(null, false, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_takeHighest_true_nullSSIDParam() { + GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); + mWiseFy.getRSSI(null, true, 1000, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getRSSIWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_takeHighest_true_nullSSIDParam_nullCallback() { + try { + mWiseFy.getRSSI(null, true, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_takeHighest_false_missingPrerequisite() { + missingPrerequisite(); + GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); + mWiseFy.getRSSI(TEST_SSID, false, 1000, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getRSSIWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_takeHighest_false_nullSSIDParam_missingPrerequisite() { + missingPrerequisite(); + try { + mWiseFy.getRSSI(TEST_SSID, false, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_takeHighest_true_missingPrerequisite() { + missingPrerequisite(); + GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); + mWiseFy.getRSSI(TEST_SSID, true, 1000, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getRSSIWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_takeHighest_true_nullSSIDParam_missingPrerequisite() { + missingPrerequisite(); + try { + mWiseFy.getRSSI(TEST_SSID, true, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_takeHighest_false_noNetworkFound() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); + mWiseFy.getRSSI(TEST_SSID, false, 1000, mockCallbacks); + verify(mockCallbacks, timeout(2000)).networkNotFoundToRetrieveRSSI(); + } + + @Test + public void callbacks_failure_takeHighest_false_noNetworkFound_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + try { + mWiseFy.getRSSI(TEST_SSID, false, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_takeHighest_true_noNetworkFound() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); + mWiseFy.getRSSI(TEST_SSID, true, 1000, mockCallbacks); + verify(mockCallbacks, timeout(2000)).networkNotFoundToRetrieveRSSI(); + } + + @Test + public void callbacks_failure_takeHighest_true_noNetworkFound_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + try { + mWiseFy.getRSSI(TEST_SSID, true, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_takeHighest_false() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.level = TEST_RSSI_LEVEL; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + + GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); + mWiseFy.getRSSI(TEST_SSID, false, 1000, mockCallbacks); + verify(mockCallbacks, timeout(2000)).retrievedRSSI(TEST_RSSI_LEVEL); + } + + @Test + public void callbacks_success_takeHighest_false_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.level = TEST_RSSI_LEVEL; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + try { + mWiseFy.getRSSI(TEST_SSID, false, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_takeHighest_true() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.level = TEST_RSSI_LEVEL; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + + GetRSSICallbacks mockCallbacks = mock(GetRSSICallbacks.class); + mWiseFy.getRSSI(TEST_SSID, true, 1000, mockCallbacks); + verify(mockCallbacks, timeout(2000)).retrievedRSSI(TEST_RSSI_LEVEL); + } + + @Test + public void callbacks_success_takeHighest_true_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.level = TEST_RSSI_LEVEL; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + try { + mWiseFy.getRSSI(TEST_SSID, true, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } +} \ No newline at end of file diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworkTests.java index 519018b5..f1bb847a 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworkTests.java @@ -1,144 +1,139 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.assertEquals; -//import static junit.framework.Assert.fail; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class GetSavedNetworkTests extends BaseTestClass { -// -// public GetSavedNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_nullSSIDParam() { -// assertEquals(null, mWiseFy.getSavedNetwork(null)); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.getSavedNetwork(TEST_SSID)); -// } -// -// @Test -// public void noCallbacks_failure() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// assertEquals(null, mWiseFy.getSavedNetwork(TEST_SSID)); -// } -// -// @Test -// public void noCallbacks_success() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// assertEquals(wiFiConfiguration, mWiseFy.getSavedNetwork(TEST_SSID)); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam() { -// GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); -// mWiseFy.getSavedNetwork(null, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).getSavedNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.getSavedNetwork(null, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); -// mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).getSavedNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.getSavedNetwork(TEST_SSID, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); -// mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).savedNetworkNotFound(); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// try { -// mWiseFy.getSavedNetwork(TEST_SSID, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); -// mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(2000)).retrievedSavedNetwork(wiFiConfiguration); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// try { -// mWiseFy.getSavedNetwork(TEST_SSID, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.callbacks.GetSavedNetworkCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class GetSavedNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_nullSSIDParam() { + assertEquals(null, mWiseFy.getSavedNetwork(null)); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getSavedNetwork(TEST_SSID)); + } + + @Test + public void noCallbacks_failure() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + assertEquals(null, mWiseFy.getSavedNetwork(TEST_SSID)); + } + + @Test + public void noCallbacks_success() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + assertEquals(wiFiConfiguration, mWiseFy.getSavedNetwork(TEST_SSID)); + } + + @Test + public void callbacks_failure_nullSSIDParam() { + GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); + mWiseFy.getSavedNetwork(null, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getSavedNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.getSavedNetwork(null, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); + mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(2000)).getSavedNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.getSavedNetwork(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); + mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(2000)).savedNetworkNotFound(); + } + + @Test + public void callbacks_failure_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + try { + mWiseFy.getSavedNetwork(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + GetSavedNetworkCallbacks mockCallbacks = mock(GetSavedNetworkCallbacks.class); + mWiseFy.getSavedNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(2000)).retrievedSavedNetwork(wiFiConfiguration); + } + + @Test + public void callbacks_success_nullCallback() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + try { + mWiseFy.getSavedNetwork(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.java index 550e8749..f96626d2 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/GetSavedNetworksTests.java @@ -1,243 +1,238 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import java.util.ArrayList; -//import java.util.List; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.assertEquals; -//import static junit.framework.Assert.fail; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class GetSavedNetworksTests extends BaseTestClass { -// -// public GetSavedNetworksTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.getSavedNetworks()); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } -// -// @Test -// public void noCallbacks_success() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// assertEquals(wifiList, mWiseFy.getSavedNetworks()); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_nullSavedNetworks() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSavedNetworksFound(); -// } -// -// @Test -// public void callbacks_failure_nullSavedNetworks_nullCallback() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); -// try { -// mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_emptyConfiguredNetworks() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSavedNetworksFound(); -// } -// -// @Test -// public void callbacks_failure_emptyConfiguredNetworks_nullCallback() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); -// try { -// mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedSavedNetworks(wifiList); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// try { -// mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_withRegex_missingPrerequisite() { -// missingPrerequisite(); -// -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } -// -// @Test -// public void noCallbacks_failure_withRegex_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.getSavedNetworks(TEST_SSID)); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } -// -// @Test -// public void noCallbacks_success_withRegex() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// assertEquals(wifiList, mWiseFy.getSavedNetworks(TEST_SSID)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); -// } -// -// @Test -// public void callbacks_failure_withRegex_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// -// try{ -// mWiseFy.getSavedNetworks(TEST_SSID, null); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_withRegex_nullSavedNetworks() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSavedNetworksFound(); -// } -// -// @Test -// public void callbacks_failure_withRegex_nullSavedNetworks_nullCallback() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); -// try { -// mWiseFy.getSavedNetworks(TEST_SSID, null); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_withRegex_emptyConfiguredNetworks() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSavedNetworksFound(); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); -// } -// -// @Test -// public void callbacks_failure_withRegex_emptyConfiguredNetworks_nullCallback() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); -// try { -// mWiseFy.getSavedNetworks(TEST_SSID, null); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_withRegex() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); -// mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedSavedNetworks(wifiList); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); -// } -// -// @Test -// public void callbacks_success_withRegex_nullCallbacks() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// -// try { -// mWiseFy.getSavedNetworks(TEST_SSID, null); -// verify(mMockWiFiManager, never()).getConfiguredNetworks(); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.callbacks.GetSavedNetworksCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class GetSavedNetworksTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getSavedNetworks()); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void noCallbacks_success() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + assertEquals(wifiList, mWiseFy.getSavedNetworks()); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_nullSavedNetworks() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSavedNetworksFound(); + } + + @Test + public void callbacks_failure_nullSavedNetworks_nullCallback() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); + try { + mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_emptyConfiguredNetworks() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSavedNetworksFound(); + } + + @Test + public void callbacks_failure_emptyConfiguredNetworks_nullCallback() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); + try { + mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedSavedNetworks(wifiList); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_success_nullCallback() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + try { + mWiseFy.getSavedNetworks((GetSavedNetworksCallbacks) null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_withRegex_missingPrerequisite() { + missingPrerequisite(); + + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).getSavedNetworksWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void noCallbacks_failure_withRegex_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.getSavedNetworks(TEST_SSID)); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } + + @Test + public void noCallbacks_success_withRegex() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + assertEquals(wifiList, mWiseFy.getSavedNetworks(TEST_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_failure_withRegex_missingPrerequisite_nullCallback() { + missingPrerequisite(); + + try{ + mWiseFy.getSavedNetworks(TEST_SSID, null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_withRegex_nullSavedNetworks() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSavedNetworksFound(); + } + + @Test + public void callbacks_failure_withRegex_nullSavedNetworks_nullCallback() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); + try { + mWiseFy.getSavedNetworks(TEST_SSID, null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_withRegex_emptyConfiguredNetworks() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSavedNetworksFound(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_failure_withRegex_emptyConfiguredNetworks_nullCallback() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); + try { + mWiseFy.getSavedNetworks(TEST_SSID, null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_withRegex() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + GetSavedNetworksCallbacks mockCallbacks = mock(GetSavedNetworksCallbacks.class); + mWiseFy.getSavedNetworks(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedSavedNetworks(wifiList); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).getConfiguredNetworks(); + } + + @Test + public void callbacks_success_withRegex_nullCallbacks() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + + try { + mWiseFy.getSavedNetworks(TEST_SSID, null); + verify(mMockWiFiManager, never()).getConfiguredNetworks(); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.java index 5a9a49cd..9353adc7 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileNetworkTests.java @@ -1,46 +1,41 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.NetworkInfo; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static junit.framework.Assert.assertFalse; -//import static junit.framework.Assert.assertTrue; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class IsDeviceConnectedToMobileNetworkTests extends BaseTestClass { -// -// public IsDeviceConnectedToMobileNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_missingPrerequisite() { -// missingPrerequisite(); -// assertFalse(mWiseFy.isDeviceConnectedToMobileNetwork()); -// } -// -// @Test -// public void failure() { -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.isNetworkConnectedAndMatchesType(any(NetworkInfo.class), anyString())).thenReturn(false); -// assertFalse(mWiseFy.isDeviceConnectedToMobileNetwork()); -// } -// -// @Test -// public void success() { -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.isNetworkConnectedAndMatchesType(any(NetworkInfo.class), anyString())).thenReturn(true); -// assertTrue(mWiseFy.isDeviceConnectedToMobileNetwork()); -// } -//} +package com.isupatches.wisefy; + + +import android.net.NetworkInfo; +import org.junit.Test; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class IsDeviceConnectedToMobileNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_missingPrerequisite() { + missingPrerequisite(); + assertFalse(mWiseFy.isDeviceConnectedToMobileNetwork()); + } + + @Test + public void failure() { + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.isNetworkConnectedAndMatchesType(any(NetworkInfo.class), anyString())).thenReturn(false); + assertFalse(mWiseFy.isDeviceConnectedToMobileNetwork()); + } + + @Test + public void success() { + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.isNetworkConnectedAndMatchesType(any(NetworkInfo.class), anyString())).thenReturn(true); + assertTrue(mWiseFy.isDeviceConnectedToMobileNetwork()); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.java index 7fe984c9..840bb8d4 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToMobileOrWifiNetworkTests.java @@ -1,45 +1,41 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.NetworkInfo; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static junit.framework.Assert.assertFalse; -//import static junit.framework.Assert.assertTrue; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class IsDeviceConnectedToMobileOrWifiNetworkTests extends BaseTestClass { -// -// public IsDeviceConnectedToMobileOrWifiNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_missingPrerequisite() { -// missingPrerequisite(); -// assertFalse(mWiseFy.isDeviceConnectedToMobileOrWifiNetwork()); -// } -// -// @Test -// public void failure() { -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.isNetworkConnected(any(NetworkInfo.class))).thenReturn(false); -// assertFalse(mWiseFy.isDeviceConnectedToMobileOrWifiNetwork()); -// } -// -// @Test -// public void success() { -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.isNetworkConnected(any(NetworkInfo.class))).thenReturn(true); -// assertTrue(mWiseFy.isDeviceConnectedToMobileOrWifiNetwork()); -// } -//} +package com.isupatches.wisefy; + + +import android.net.NetworkInfo; +import com.isupatches.wisefy.base.TestActivity; +import org.junit.Test; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class IsDeviceConnectedToMobileOrWifiNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_missingPrerequisite() { + missingPrerequisite(); + assertFalse(mWiseFy.isDeviceConnectedToMobileOrWifiNetwork()); + } + + @Test + public void failure() { + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.isNetworkConnected(any(NetworkInfo.class))).thenReturn(false); + assertFalse(mWiseFy.isDeviceConnectedToMobileOrWifiNetwork()); + } + + @Test + public void success() { + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.isNetworkConnected(any(NetworkInfo.class))).thenReturn(true); + assertTrue(mWiseFy.isDeviceConnectedToMobileOrWifiNetwork()); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.java index faadaec3..adceb5d9 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToSSIDTests.java @@ -1,48 +1,43 @@ -//package com.isupatches.wisefy; -// -// -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.assertFalse; -//import static junit.framework.Assert.assertTrue; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class IsDeviceConnectedToSSIDTests extends BaseTestClass { -// -// public IsDeviceConnectedToSSIDTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_nullSSIDParams() { -// assertFalse(mWiseFy.isDeviceConnectedToSSID(null)); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertFalse(mWiseFy.isDeviceConnectedToSSID(TEST_SSID)); -// } -// -// @Test -// public void noCallbacks_failure() { -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.isCurrentNetworkConnectedToSSID(anyString())).thenReturn(false); -// -// assertFalse(mWiseFy.isDeviceConnectedToSSID(TEST_SSID)); -// } -// -// @Test -// public void noCallbacks_success() { -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.isCurrentNetworkConnectedToSSID(anyString())).thenReturn(true); -// -// assertTrue(mWiseFy.isDeviceConnectedToSSID(TEST_SSID)); -// } -//} +package com.isupatches.wisefy; + + +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class IsDeviceConnectedToSSIDTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_nullSSIDParams() { + assertFalse(mWiseFy.isDeviceConnectedToSSID(null)); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertFalse(mWiseFy.isDeviceConnectedToSSID(TEST_SSID)); + } + + @Test + public void noCallbacks_failure() { + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.isCurrentNetworkConnectedToSSID(anyString())).thenReturn(false); + + assertFalse(mWiseFy.isDeviceConnectedToSSID(TEST_SSID)); + } + + @Test + public void noCallbacks_success() { + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.isCurrentNetworkConnectedToSSID(anyString())).thenReturn(true); + + assertTrue(mWiseFy.isDeviceConnectedToSSID(TEST_SSID)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.java index 0c4495f6..da3d209d 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceConnectedToWifiNetworkTests.java @@ -1,46 +1,41 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.NetworkInfo; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static junit.framework.Assert.assertFalse; -//import static junit.framework.Assert.assertTrue; -//import static org.mockito.ArgumentMatchers.any; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class IsDeviceConnectedToWifiNetworkTests extends BaseTestClass { -// -// public IsDeviceConnectedToWifiNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_missingPrerequisite() { -// missingPrerequisite(); -// assertFalse(mWiseFy.isDeviceConnectedToWifiNetwork()); -// } -// -// @Test -// public void failure() { -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.isNetworkConnectedAndMatchesType(any(NetworkInfo.class), anyString())).thenReturn(false); -// assertFalse(mWiseFy.isDeviceConnectedToWifiNetwork()); -// } -// -// @Test -// public void success() { -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); -// -// WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); -// mWiseFy.mWiseFyConnection = mockWiseFyConnection; -// when(mockWiseFyConnection.isNetworkConnectedAndMatchesType(any(NetworkInfo.class), anyString())).thenReturn(true); -// assertTrue(mWiseFy.isDeviceConnectedToWifiNetwork()); -// } -//} +package com.isupatches.wisefy; + + +import android.net.NetworkInfo; +import org.junit.Test; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class IsDeviceConnectedToWifiNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_missingPrerequisite() { + missingPrerequisite(); + assertFalse(mWiseFy.isDeviceConnectedToWifiNetwork()); + } + + @Test + public void failure() { + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.isNetworkConnectedAndMatchesType(any(NetworkInfo.class), anyString())).thenReturn(false); + assertFalse(mWiseFy.isDeviceConnectedToWifiNetwork()); + } + + @Test + public void success() { + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(mock(NetworkInfo.class)); + + WiseFyConnection mockWiseFyConnection = mock(WiseFyConnection.class); + mWiseFy.mWiseFyConnection = mockWiseFyConnection; + when(mockWiseFyConnection.isNetworkConnectedAndMatchesType(any(NetworkInfo.class), anyString())).thenReturn(true); + assertTrue(mWiseFy.isDeviceConnectedToWifiNetwork()); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceRoamingTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceRoamingTests.java index a02cbc6f..7e214cb1 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceRoamingTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsDeviceRoamingTests.java @@ -1,42 +1,37 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.NetworkInfo; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static junit.framework.Assert.assertFalse; -//import static junit.framework.Assert.assertTrue; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class IsDeviceRoamingTests extends BaseTestClass { -// -// public IsDeviceRoamingTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_missingPrerequisite() { -// missingPrerequisite(); -// assertFalse(mWiseFy.isDeviceRoaming()); -// } -// -// @Test -// public void failure() { -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isRoaming()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(mWiseFy.isDeviceRoaming()); -// } -// -// @Test -// public void success() { -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isRoaming()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertTrue(mWiseFy.isDeviceRoaming()); -// } -//} +package com.isupatches.wisefy; + + +import android.net.NetworkInfo; +import org.junit.Test; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class IsDeviceRoamingTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_missingPrerequisite() { + missingPrerequisite(); + assertFalse(mWiseFy.isDeviceRoaming()); + } + + @Test + public void failure() { + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isRoaming()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(mWiseFy.isDeviceRoaming()); + } + + @Test + public void success() { + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isRoaming()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertTrue(mWiseFy.isDeviceRoaming()); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.java index f9de44d0..0af93446 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetwork5gHzTests.java @@ -1,102 +1,97 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiInfo; -//import android.os.Build; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_5GHZ; -//import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_ABOVE_5GHZ; -//import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_BELOW_5GHZ; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class IsNetwork5gHzTests extends BaseTestClass { -// -// public IsNetwork5gHzTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void currentNetwork_failure_above5ghz() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(false, mWiseFy.isNetwork5gHz()); -// } -// } -// -// @Test -// public void currentNetwork_failure_below5ghz() { -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(false, mWiseFy.isNetwork5gHz()); -// } -// } -// -// @Test -// public void currentNetwork_failure_null() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// assertEquals(false, mWiseFy.isNetwork5gHz()); -// } -// } -// -// @Test -// public void currentNetwork_success() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(true, mWiseFy.isNetwork5gHz()); -// } -// } -// -// @Test -// public void provideWifiInfo_failure_above5ghz() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo)); -// } -// } -// -// @Test -// public void provideWifiInfo_failure_below5ghz() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo)); -// } -// } -// -// @Test -// public void provideWifiInfo_failure_null() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// assertEquals(false, mWiseFy.isNetwork5gHz(null)); -// } -// } -// -// @Test -// public void provideWifiInfo_success() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { -// WifiInfo mockWifiInfo = mock(WifiInfo.class); -// when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); -// -// assertEquals(true, mWiseFy.isNetwork5gHz(mockWifiInfo)); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiInfo; +import android.os.Build; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_5GHZ; +import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_ABOVE_5GHZ; +import static com.isupatches.wisefy.base.TestUtils.TEST_NETWORK_FREQUENCY_BELOW_5GHZ; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class IsNetwork5gHzTests extends BaseAndroidJUnit4TestClass { + + @Test + public void currentNetwork_failure_above5ghz() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(false, mWiseFy.isNetwork5gHz()); + } + } + + @Test + public void currentNetwork_failure_below5ghz() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(false, mWiseFy.isNetwork5gHz()); + } + } + + @Test + public void currentNetwork_failure_null() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + assertEquals(false, mWiseFy.isNetwork5gHz()); + } + } + + @Test + public void currentNetwork_success() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(true, mWiseFy.isNetwork5gHz()); + } + } + + @Test + public void provideWifiInfo_failure_above5ghz() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo)); + } + } + + @Test + public void provideWifiInfo_failure_below5ghz() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo)); + } + } + + @Test + public void provideWifiInfo_failure_null() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + assertEquals(false, mWiseFy.isNetwork5gHz(null)); + } + } + + @Test + public void provideWifiInfo_success() { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + WifiInfo mockWifiInfo = mock(WifiInfo.class); + when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo); + + assertEquals(true, mWiseFy.isNetwork5gHz(mockWifiInfo)); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkEAPTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkEAPTests.java index 608760ca..51a45406 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkEAPTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkEAPTests.java @@ -1,49 +1,44 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.constants.Capabilities; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -// -// -//public class IsNetworkEAPTests extends BaseTestClass { -// -// public IsNetworkEAPTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_differentCapability() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = "Other"; -// assertEquals(false, mWiseFy.isNetworkEAP(scanResult)); -// } -// -// @Test -// public void failure_emptyCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = ""; -// assertEquals(false, mWiseFy.isNetworkEAP(scanResult)); -// } -// -// @Test -// public void failure_nullCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// assertEquals(false, mWiseFy.isNetworkEAP(scanResult)); -// } -// -// @Test -// public void failure_nullScanResult() { -// assertEquals(false, mWiseFy.isNetworkEAP(null)); -// } -// -// @Test -// public void success() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.EAP; -// assertEquals(true, mWiseFy.isNetworkEAP(scanResult)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.constants.Capabilities; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + + +public class IsNetworkEAPTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_differentCapability() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "Other"; + assertEquals(false, mWiseFy.isNetworkEAP(scanResult)); + } + + @Test + public void failure_emptyCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = ""; + assertEquals(false, mWiseFy.isNetworkEAP(scanResult)); + } + + @Test + public void failure_nullCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + assertEquals(false, mWiseFy.isNetworkEAP(scanResult)); + } + + @Test + public void failure_nullScanResult() { + assertEquals(false, mWiseFy.isNetworkEAP(null)); + } + + @Test + public void success() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.EAP; + assertEquals(true, mWiseFy.isNetworkEAP(scanResult)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkInConfigurationListTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkInConfigurationListTests.java index b17936f8..b2981cd2 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkInConfigurationListTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkInConfigurationListTests.java @@ -1,99 +1,94 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import java.util.ArrayList; -//import java.util.List; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID3; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.when; -// -// -//public class IsNetworkInConfigurationListTests extends BaseTestClass { -// -// public IsNetworkInConfigurationListTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure() { -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_multipleNetworks() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); -// wifiConfiguration1.SSID = TEST_SSID2; -// wifiList.add(wifiConfiguration1); -// -// WifiConfiguration wiFiConfiguration2 = new WifiConfiguration(); -// wiFiConfiguration2.SSID = TEST_SSID3; -// wifiList.add(wiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_noNetworks() { -// List wifiList = new ArrayList<>(); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_nullSSID() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration wifiConfiguration = new WifiConfiguration(); -// wifiConfiguration.SSID = null; -// wifiList.add(wifiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_nullWifiConfiguration() { -// List wifiList = new ArrayList<>(); -// wifiList.add(0, null); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void failure_nmissingPrerequisite() { -// missingPrerequisite(); -// assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void success() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -// -// @Test -// public void success_multipleNetworks() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); -// wifiConfiguration1.SSID = TEST_SSID; -// wifiList.add(wifiConfiguration1); -// -// WifiConfiguration wiFiConfiguration2 = new WifiConfiguration(); -// wiFiConfiguration2.SSID = TEST_SSID2; -// wifiList.add(wiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID3; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + + +public class IsNetworkInConfigurationListTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure() { + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_multipleNetworks() { + List wifiList = new ArrayList<>(); + + WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); + wifiConfiguration1.SSID = TEST_SSID2; + wifiList.add(wifiConfiguration1); + + WifiConfiguration wiFiConfiguration2 = new WifiConfiguration(); + wiFiConfiguration2.SSID = TEST_SSID3; + wifiList.add(wiFiConfiguration2); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_noNetworks() { + List wifiList = new ArrayList<>(); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_nullSSID() { + List wifiList = new ArrayList<>(); + WifiConfiguration wifiConfiguration = new WifiConfiguration(); + wifiConfiguration.SSID = null; + wifiList.add(wifiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_nullWifiConfiguration() { + List wifiList = new ArrayList<>(); + wifiList.add(0, null); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void failure_nmissingPrerequisite() { + missingPrerequisite(); + assertEquals(false, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void success() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } + + @Test + public void success_multipleNetworks() { + List wifiList = new ArrayList<>(); + + WifiConfiguration wifiConfiguration1 = new WifiConfiguration(); + wifiConfiguration1.SSID = TEST_SSID; + wifiList.add(wifiConfiguration1); + + WifiConfiguration wiFiConfiguration2 = new WifiConfiguration(); + wiFiConfiguration2.SSID = TEST_SSID2; + wifiList.add(wiFiConfiguration2); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(true, mWiseFy.isNetworkInConfigurationList(TEST_SSID)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkPSKTest.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkPSKTest.java index 7a307f68..5ac26f84 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkPSKTest.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkPSKTest.java @@ -1,49 +1,44 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.constants.Capabilities; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -// -// -//public class IsNetworkPSKTest extends BaseTestClass { -// -// public IsNetworkPSKTest() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_differentCapability() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = "Other"; -// assertEquals(false, mWiseFy.isNetworkPSK(scanResult)); -// } -// -// @Test -// public void failure_emptyCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = ""; -// assertEquals(false, mWiseFy.isNetworkPSK(scanResult)); -// } -// -// @Test -// public void failure_nullCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// assertEquals(false, mWiseFy.isNetworkPSK(scanResult)); -// } -// -// @Test -// public void failure_nullScanResult() { -// assertEquals(false, mWiseFy.isNetworkPSK(null)); -// } -// -// @Test -// public void success() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.PSK; -// assertEquals(true, mWiseFy.isNetworkPSK(scanResult)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.constants.Capabilities; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + + +public class IsNetworkPSKTest extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_differentCapability() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "Other"; + assertEquals(false, mWiseFy.isNetworkPSK(scanResult)); + } + + @Test + public void failure_emptyCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = ""; + assertEquals(false, mWiseFy.isNetworkPSK(scanResult)); + } + + @Test + public void failure_nullCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + assertEquals(false, mWiseFy.isNetworkPSK(scanResult)); + } + + @Test + public void failure_nullScanResult() { + assertEquals(false, mWiseFy.isNetworkPSK(null)); + } + + @Test + public void success() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.PSK; + assertEquals(true, mWiseFy.isNetworkPSK(scanResult)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSecureTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSecureTests.java index 89a450b1..cd3823ec 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSecureTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkSecureTests.java @@ -1,77 +1,72 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.constants.Capabilities; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -// -// -//public class IsNetworkSecureTests extends BaseTestClass { -// -// public IsNetworkSecureTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_emptyCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = ""; -// assertEquals(false, mWiseFy.isNetworkSecure(scanResult)); -// } -// -// @Test -// public void failure_nullCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// assertEquals(false, mWiseFy.isNetworkSecure(scanResult)); -// } -// -// @Test -// public void failure_nullScanResult() { -// assertEquals(false, mWiseFy.isNetworkSecure(null)); -// } -// -// @Test -// public void success_withEAP() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.EAP; -// assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); -// } -// -// @Test -// public void success_withPSK() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.PSK; -// assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); -// } -// -// @Test -// public void success_withWEP() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.WEP; -// assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); -// } -// -// @Test -// public void success_withWPA() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.WPA; -// assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); -// } -// -// @Test -// public void success_withWPA2() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.WPA2; -// assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); -// } -// -// @Test -// public void failure_otherCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = "Other"; -// assertEquals(false, mWiseFy.isNetworkSecure(scanResult)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.constants.Capabilities; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + + +public class IsNetworkSecureTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_emptyCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = ""; + assertEquals(false, mWiseFy.isNetworkSecure(scanResult)); + } + + @Test + public void failure_nullCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + assertEquals(false, mWiseFy.isNetworkSecure(scanResult)); + } + + @Test + public void failure_nullScanResult() { + assertEquals(false, mWiseFy.isNetworkSecure(null)); + } + + @Test + public void success_withEAP() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.EAP; + assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); + } + + @Test + public void success_withPSK() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.PSK; + assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); + } + + @Test + public void success_withWEP() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.WEP; + assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); + } + + @Test + public void success_withWPA() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.WPA; + assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); + } + + @Test + public void success_withWPA2() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.WPA2; + assertEquals(true, mWiseFy.isNetworkSecure(scanResult)); + } + + @Test + public void failure_otherCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "Other"; + assertEquals(false, mWiseFy.isNetworkSecure(scanResult)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPA2Test.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPA2Test.java index e148472f..48f98ada 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPA2Test.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPA2Test.java @@ -1,49 +1,44 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.constants.Capabilities; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -// -// -//public class IsNetworkWPA2Test extends BaseTestClass { -// -// public IsNetworkWPA2Test() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_differentCapability() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = "Other"; -// assertEquals(false, mWiseFy.isNetworkWPA2(scanResult)); -// } -// -// @Test -// public void failure_emptyCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = ""; -// assertEquals(false, mWiseFy.isNetworkWPA2(scanResult)); -// } -// -// @Test -// public void failure_nullCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// assertEquals(false, mWiseFy.isNetworkWPA2(scanResult)); -// } -// -// @Test -// public void failure_nullScanResult() { -// assertEquals(false, mWiseFy.isNetworkWPA2(null)); -// } -// -// @Test -// public void success() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.WPA2; -// assertEquals(true, mWiseFy.isNetworkWPA2(scanResult)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.constants.Capabilities; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + + +public class IsNetworkWPA2Test extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_differentCapability() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "Other"; + assertEquals(false, mWiseFy.isNetworkWPA2(scanResult)); + } + + @Test + public void failure_emptyCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = ""; + assertEquals(false, mWiseFy.isNetworkWPA2(scanResult)); + } + + @Test + public void failure_nullCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + assertEquals(false, mWiseFy.isNetworkWPA2(scanResult)); + } + + @Test + public void failure_nullScanResult() { + assertEquals(false, mWiseFy.isNetworkWPA2(null)); + } + + @Test + public void success() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.WPA2; + assertEquals(true, mWiseFy.isNetworkWPA2(scanResult)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPATests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPATests.java index b87bebe6..64793f87 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPATests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWPATests.java @@ -1,49 +1,44 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.constants.Capabilities; -//import org.junit.Test; -//import static junit.framework.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -// -// -//public class IsNetworkWPATests extends BaseTestClass { -// -// public IsNetworkWPATests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_differentCapability() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = "Other"; -// assertEquals(false, mWiseFy.isNetworkWPA(scanResult)); -// } -// -// @Test -// public void failure_emptyCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = ""; -// assertEquals(false, mWiseFy.isNetworkWPA(scanResult)); -// } -// -// @Test -// public void failure_nullCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// assertEquals(false, mWiseFy.isNetworkWPA(scanResult)); -// } -// -// @Test -// public void failure_nullScanResult() { -// assertEquals(false, mWiseFy.isNetworkWPA(null)); -// } -// -// @Test -// public void success() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.WPA; -// assertEquals(true, mWiseFy.isNetworkWPA(scanResult)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.constants.Capabilities; +import org.junit.Test; +import static junit.framework.Assert.assertEquals; +import static org.mockito.Mockito.mock; + + +public class IsNetworkWPATests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_differentCapability() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "Other"; + assertEquals(false, mWiseFy.isNetworkWPA(scanResult)); + } + + @Test + public void failure_emptyCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = ""; + assertEquals(false, mWiseFy.isNetworkWPA(scanResult)); + } + + @Test + public void failure_nullCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + assertEquals(false, mWiseFy.isNetworkWPA(scanResult)); + } + + @Test + public void failure_nullScanResult() { + assertEquals(false, mWiseFy.isNetworkWPA(null)); + } + + @Test + public void success() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.WPA; + assertEquals(true, mWiseFy.isNetworkWPA(scanResult)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWepTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWepTests.java index b6bd3176..e94e8d90 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWepTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsNetworkWepTests.java @@ -1,49 +1,44 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.constants.Capabilities; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -// -// -//public class IsNetworkWepTests extends BaseTestClass { -// -// public IsNetworkWepTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure_differentCapability() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = "Other"; -// assertEquals(false, mWiseFy.isNetworkWEP(scanResult)); -// } -// -// @Test -// public void failure_emptyCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = ""; -// assertEquals(false, mWiseFy.isNetworkWEP(scanResult)); -// } -// -// @Test -// public void failure_nullCapabilities() { -// ScanResult scanResult = mock(ScanResult.class); -// assertEquals(false, mWiseFy.isNetworkWEP(scanResult)); -// } -// -// @Test -// public void failure_nullScanResult() { -// assertEquals(false, mWiseFy.isNetworkWEP(null)); -// } -// -// @Test -// public void success() { -// ScanResult scanResult = mock(ScanResult.class); -// scanResult.capabilities = Capabilities.WEP; -// assertEquals(true, mWiseFy.isNetworkWEP(scanResult)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.constants.Capabilities; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + + +public class IsNetworkWepTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure_differentCapability() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "Other"; + assertEquals(false, mWiseFy.isNetworkWEP(scanResult)); + } + + @Test + public void failure_emptyCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = ""; + assertEquals(false, mWiseFy.isNetworkWEP(scanResult)); + } + + @Test + public void failure_nullCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + assertEquals(false, mWiseFy.isNetworkWEP(scanResult)); + } + + @Test + public void failure_nullScanResult() { + assertEquals(false, mWiseFy.isNetworkWEP(null)); + } + + @Test + public void success() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = Capabilities.WEP; + assertEquals(true, mWiseFy.isNetworkWEP(scanResult)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsWifiEnabledTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsWifiEnabledTests.java index cfd47f86..25bb11cb 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/IsWifiEnabledTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/IsWifiEnabledTests.java @@ -1,33 +1,28 @@ -//package com.isupatches.wisefy; -// -// -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.Mockito.when; -// -// -//public class IsWifiEnabledTests extends BaseTestClass { -// -// public IsWifiEnabledTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void failure() { -// when(mMockWiFiManager.isWifiEnabled()).thenReturn(false); -// assertEquals(false, mWiseFy.isWifiEnabled()); -// } -// -// @Test -// public void failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(false, mWiseFy.isWifiEnabled()); -// } -// -// @Test -// public void success() { -// when(mMockWiFiManager.isWifiEnabled()).thenReturn(true); -// assertEquals(true, mWiseFy.isWifiEnabled()); -// } -//} \ No newline at end of file +package com.isupatches.wisefy; + + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + + +public class IsWifiEnabledTests extends BaseAndroidJUnit4TestClass { + + @Test + public void failure() { + when(mMockWiFiManager.isWifiEnabled()).thenReturn(false); + assertEquals(false, mWiseFy.isWifiEnabled()); + } + + @Test + public void failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(false, mWiseFy.isWifiEnabled()); + } + + @Test + public void success() { + when(mMockWiFiManager.isWifiEnabled()).thenReturn(true); + assertEquals(true, mWiseFy.isWifiEnabled()); + } +} \ No newline at end of file diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/ManagerUtilTest.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/ManagerUtilTest.java index 3ae49076..43a8da60 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/ManagerUtilTest.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/ManagerUtilTest.java @@ -1,46 +1,37 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.ConnectivityManager; -//import android.net.wifi.WifiManager; -//import android.support.test.rule.ActivityTestRule; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.util.ManagerUtil; -//import org.junit.Rule; -//import org.junit.Test; -//import static junit.framework.Assert.*; -// -// -//public class ManagerUtilTest extends BaseTestClass { -// -// public ManagerUtilTest() { -// super(TestActivity.class); -// } -// -// @Rule -// public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(TestActivity.class); -// -// @Test -// public void getConnectivityManager_returnsNotNull() { -// ConnectivityManager connectivityManager = ManagerUtil.getInstance().getConnectivityManager(mActivityTestRule.getActivity()); -// assertNotNull(connectivityManager); -// } -// -// @Test -// public void getConnectivityManager_returnsNull_noActivity() { -// ConnectivityManager connectivityManager = ManagerUtil.getInstance().getConnectivityManager(null); -// assertNull(connectivityManager); -// } -// -// @Test -// public void getWiFiManager_returnsNotNull() { -// WifiManager wifiManager = ManagerUtil.getInstance().getWiFiManager(mActivityTestRule.getActivity()); -// assertNotNull(wifiManager); -// } -// -// @Test -// public void getWiFiManager_returnsNull_noActivity() { -// WifiManager wifiManager = ManagerUtil.getInstance().getWiFiManager(null); -// assertNull(wifiManager); -// } -//} \ No newline at end of file +package com.isupatches.wisefy; + + +import android.net.ConnectivityManager; +import android.net.wifi.WifiManager; +import android.support.test.InstrumentationRegistry; +import com.isupatches.wisefy.util.ManagerUtil; +import org.junit.Test; +import static junit.framework.Assert.*; + + +public class ManagerUtilTest extends BaseAndroidJUnit4TestClass { + + @Test + public void getConnectivityManager_returnsNotNull() { + ConnectivityManager connectivityManager = ManagerUtil.getInstance().getConnectivityManager(InstrumentationRegistry.getContext()); + assertNotNull(connectivityManager); + } + + @Test + public void getConnectivityManager_returnsNull_noActivity() { + ConnectivityManager connectivityManager = ManagerUtil.getInstance().getConnectivityManager(null); + assertNull(connectivityManager); + } + + @Test + public void getWiFiManager_returnsNotNull() { + WifiManager wifiManager = ManagerUtil.getInstance().getWiFiManager(InstrumentationRegistry.getContext()); + assertNotNull(wifiManager); + } + + @Test + public void getWiFiManager_returnsNull_noActivity() { + WifiManager wifiManager = ManagerUtil.getInstance().getWiFiManager(null); + assertNull(wifiManager); + } +} \ No newline at end of file diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.java index 1de0d46a..ae3f5a42 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/RemoveNetworkTests.java @@ -1,210 +1,205 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static org.junit.Assert.assertEquals; -//import static org.junit.Assert.fail; -//import static org.mockito.ArgumentMatchers.anyInt; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.never; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class RemoveNetworkTests extends BaseTestClass { -// -// public RemoveNetworkTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_nullSSIDParam() { -// assertEquals(false, mWiseFy.removeNetwork(null)); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisites() { -// missingPrerequisite(); -// assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } -// -// @Test -// public void noCallbacks_failure_noSavedNetwork() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } -// -// @Test -// public void noCallbacks_failure() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); -// -// assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); -// -// } -// -// @Test -// public void noCallbacks_success() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(true); -// -// assertEquals(true, mWiseFy.removeNetwork(TEST_SSID)); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam() { -// RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); -// mWiseFy.removeNetwork(null, mockCallbacks); -// verify(mockCallbacks, timeout(3000)).removeNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.removeNetwork(null, null); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisites() { -// missingPrerequisite(); -// RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); -// mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).removeNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisites_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.removeNetwork(TEST_SSID, null); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_noSavedNetwork() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); -// mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkNotFoundToRemove(); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } -// -// @Test -// public void callbacks_failure_noSavedNetwork_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); -// -// try { -// mWiseFy.removeNetwork(TEST_SSID, null); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); -// -// RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); -// mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureRemovingNetwork(); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); -// } -// -// @Test -// public void callbacks_failure_nullCallback() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); -// -// try { -// mWiseFy.removeNetwork(TEST_SSID, null); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(true); -// -// RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); -// mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkRemoved(); -// verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// WifiConfiguration wiFiConfiguration = new WifiConfiguration(); -// wiFiConfiguration.SSID = TEST_SSID; -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); -// -// when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(true); -// -// try { -// mWiseFy.removeNetwork(TEST_SSID, null); -// verify(mMockWiFiManager, never()).removeNetwork(anyInt()); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.WifiConfiguration; +import com.isupatches.wisefy.callbacks.RemoveNetworkCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class RemoveNetworkTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_nullSSIDParam() { + assertEquals(false, mWiseFy.removeNetwork(null)); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } + + @Test + public void noCallbacks_failure_missingPrerequisites() { + missingPrerequisite(); + assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } + + @Test + public void noCallbacks_failure_noSavedNetwork() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } + + @Test + public void noCallbacks_failure() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); + + assertEquals(false, mWiseFy.removeNetwork(TEST_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); + + } + + @Test + public void noCallbacks_success() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(true); + + assertEquals(true, mWiseFy.removeNetwork(TEST_SSID)); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); + } + + @Test + public void callbacks_failure_nullSSIDParam() { + RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); + mWiseFy.removeNetwork(null, mockCallbacks); + verify(mockCallbacks, timeout(3000)).removeNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.removeNetwork(null, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisites() { + missingPrerequisite(); + RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); + mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).removeNetworkWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } + + @Test + public void callbacks_failure_missingPrerequisites_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.removeNetwork(TEST_SSID, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_noSavedNetwork() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); + mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkNotFoundToRemove(); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } + + @Test + public void callbacks_failure_noSavedNetwork_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(null); + + try { + mWiseFy.removeNetwork(TEST_SSID, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); + + RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); + mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).failureRemovingNetwork(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); + } + + @Test + public void callbacks_failure_nullCallback() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(false); + + try { + mWiseFy.removeNetwork(TEST_SSID, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(true); + + RemoveNetworkCallbacks mockCallbacks = mock(RemoveNetworkCallbacks.class); + mWiseFy.removeNetwork(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).networkRemoved(); + verify(mMockWiFiManager, timeout(VERIFICATION_TIMEOUT)).removeNetwork(anyInt()); + } + + @Test + public void callbacks_success_nullCallback() { + WifiConfiguration wiFiConfiguration = new WifiConfiguration(); + wiFiConfiguration.SSID = TEST_SSID; + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSavedNetworkByRegex(anyString())).thenReturn(wiFiConfiguration); + + when(mMockWiFiManager.removeNetwork(anyInt())).thenReturn(true); + + try { + mWiseFy.removeNetwork(TEST_SSID, null); + verify(mMockWiFiManager, never()).removeNetwork(anyInt()); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointTests.java index 5f80d28a..b83f885f 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointTests.java @@ -1,272 +1,267 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.assertEquals; -//import static junit.framework.Assert.fail; -//import static org.mockito.ArgumentMatchers.anyBoolean; -//import static org.mockito.ArgumentMatchers.anyInt; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class SearchForAccessPointTests extends BaseTestClass { -// -// public SearchForAccessPointTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_false_nullSSIDParam() { -// assertEquals(null, mWiseFy.searchForAccessPoint(null, 1000, false)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_true_nullSSIDParam() { -// assertEquals(null, mWiseFy.searchForAccessPoint(null, 1000, true)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_false_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_true_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_false() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// assertEquals(null, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_true() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// assertEquals(null, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void noCallbacks_success_filterDuplicates_false() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// assertEquals(accessPoint, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void noCallbacks_success_filterDuplicates_true() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// assertEquals(accessPoint, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_nullSSIDParam() { -// SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); -// mWiseFy.searchForAccessPoint(null, 1000, false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.searchForAccessPoint(null, 1000, false, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true_nullSSIDParam() { -// SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); -// mWiseFy.searchForAccessPoint(null, 1000, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.searchForAccessPoint(null, 1000, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_missingPrerequisite() { -// missingPrerequisite(); -// SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true_missingPrerequisite() { -// missingPrerequisite(); -// SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).accessPointNotFound(); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// try { -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).accessPointNotFound(); -// } -// -// -// @Test -// public void callbacks_failure_filterDuplicates_true_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// try { -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_filterDuplicates_false() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).accessPointFound(accessPoint); -// } -// -// @Test -// public void callbacks_success_filterDuplicates_false_nullCallback() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// try { -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_filterDuplicates_true() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).accessPointFound(accessPoint); -// } -// -// @Test -// public void callbacks_success_filterDuplicates_true_nullCallback() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// try { -// mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.callbacks.SearchForAccessPointCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class SearchForAccessPointTests extends BaseAndroidJUnit4TestClass{ + + @Test + public void noCallbacks_failure_filterDuplicates_false_nullSSIDParam() { + assertEquals(null, mWiseFy.searchForAccessPoint(null, 1000, false)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_true_nullSSIDParam() { + assertEquals(null, mWiseFy.searchForAccessPoint(null, 1000, true)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_false_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_true_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_false() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + assertEquals(null, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_true() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + assertEquals(null, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true)); + } + + @Test + public void noCallbacks_success_filterDuplicates_false() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + assertEquals(accessPoint, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false)); + } + + @Test + public void noCallbacks_success_filterDuplicates_true() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + assertEquals(accessPoint, mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true)); + } + + @Test + public void callbacks_failure_filterDuplicates_false_nullSSIDParam() { + SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); + mWiseFy.searchForAccessPoint(null, 1000, false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_filterDuplicates_false_nullSSIDParam_nullCallback() { + try { + mWiseFy.searchForAccessPoint(null, 1000, false, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_true_nullSSIDParam() { + SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); + mWiseFy.searchForAccessPoint(null, 1000, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_filterDuplicates_true_nullSSIDParam_nullCallback() { + try { + mWiseFy.searchForAccessPoint(null, 1000, true, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_false_missingPrerequisite() { + missingPrerequisite(); + SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_filterDuplicates_false_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_true_missingPrerequisite() { + missingPrerequisite(); + SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_filterDuplicates_true_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_false() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).accessPointNotFound(); + } + + @Test + public void callbacks_failure_filterDuplicates_false_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + try { + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_true() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).accessPointNotFound(); + } + + + @Test + public void callbacks_failure_filterDuplicates_true_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + try { + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_filterDuplicates_false() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).accessPointFound(accessPoint); + } + + @Test + public void callbacks_success_filterDuplicates_false_nullCallback() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + try { + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, false, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_filterDuplicates_true() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + SearchForAccessPointCallbacks mockCallbacks = mock(SearchForAccessPointCallbacks.class); + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).accessPointFound(accessPoint); + } + + @Test + public void callbacks_success_filterDuplicates_true_nullCallback() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + try { + mWiseFy.searchForAccessPoint(TEST_SSID, 1000, true, null); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointsTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointsTests.java index 9b4eecd6..7a073b3a 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointsTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForAccessPointsTests.java @@ -1,286 +1,282 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import java.util.ArrayList; -//import java.util.List; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.assertEquals; -//import static junit.framework.Assert.fail; -//import static org.mockito.ArgumentMatchers.anyBoolean; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class SearchForAccessPointsTests extends BaseTestClass { -// -// public SearchForAccessPointsTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_false_nullSSIDParam() { -// assertEquals(null, mWiseFy.searchForAccessPoints(null, false)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_true_nullSSIDParam() { -// assertEquals(null, mWiseFy.searchForAccessPoints(null, true)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_false_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.searchForAccessPoints(TEST_SSID, false)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_true_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.searchForAccessPoints(TEST_SSID, true)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_false() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); -// -// assertEquals(null, mWiseFy.searchForAccessPoints(TEST_SSID, false)); -// } -// -// @Test -// public void noCallbacks_failure_filterDuplicates_true() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); -// -// assertEquals(null, mWiseFy.searchForAccessPoints(TEST_SSID, true)); -// } -// -// @Test -// public void noCallbacks_success_filterDuplicates_false() { -// List accessPoints = new ArrayList<>(); -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// accessPoints.add(accessPoint); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); -// -// assertEquals(accessPoints, mWiseFy.searchForAccessPoints(TEST_SSID, false)); -// } -// -// @Test -// public void noCallbacks_success_filterDuplicates_true() { -// List accessPoints = new ArrayList<>(); -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// accessPoints.add(accessPoint); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); -// -// assertEquals(accessPoints, mWiseFy.searchForAccessPoints(TEST_SSID, true)); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_nullSSIDParam() { -// SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); -// mWiseFy.searchForAccessPoints(null, false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.searchForAccessPoints(null, false, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true_nullSSIDParam() { -// SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); -// mWiseFy.searchForAccessPoints(null, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.searchForAccessPoints(null, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_missingPrerequisite() { -// missingPrerequisite(); -// SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); -// mWiseFy.searchForAccessPoints(TEST_SSID, false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.searchForAccessPoints(TEST_SSID, false, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true_missingPrerequisite() { -// missingPrerequisite(); -// SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); -// mWiseFy.searchForAccessPoints(TEST_SSID, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.searchForAccessPoints(TEST_SSID, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); -// -// SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); -// mWiseFy.searchForAccessPoints(TEST_SSID, false, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noAccessPointsFound(); -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_false_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); -// -// try { -// mWiseFy.searchForAccessPoints(TEST_SSID, false, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_filterDuplicates_true() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); -// -// SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); -// mWiseFy.searchForAccessPoints(TEST_SSID, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noAccessPointsFound(); -// } -// -// -// @Test -// public void callbacks_failure_filterDuplicates_true_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); -// -// try { -// mWiseFy.searchForAccessPoints(TEST_SSID, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_filterDuplicates_false() { -// List accessPoints = new ArrayList<>(); -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// accessPoints.add(accessPoint); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); -// -// SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); -// mWiseFy.searchForAccessPoints(TEST_SSID, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).foundAccessPoints(accessPoints); -// } -// -// @Test -// public void callbacks_success_filterDuplicates_false_nullCallback() { -// List accessPoints = new ArrayList<>(); -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// accessPoints.add(accessPoint); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); -// -// try { -// mWiseFy.searchForAccessPoints(TEST_SSID, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success_filterDuplicates_true() { -// List accessPoints = new ArrayList<>(); -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// accessPoints.add(accessPoint); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); -// -// SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); -// mWiseFy.searchForAccessPoints(TEST_SSID, true, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).foundAccessPoints(accessPoints); -// } -// -// @Test -// public void callbacks_success_filterDuplicates_true_nullCallback() { -// List accessPoints = new ArrayList<>(); -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// accessPoints.add(accessPoint); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); -// -// try { -// mWiseFy.searchForAccessPoints(TEST_SSID, true, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.base.TestActivity; +import com.isupatches.wisefy.callbacks.SearchForAccessPointsCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.fail; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class SearchForAccessPointsTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_filterDuplicates_false_nullSSIDParam() { + assertEquals(null, mWiseFy.searchForAccessPoints(null, false)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_true_nullSSIDParam() { + assertEquals(null, mWiseFy.searchForAccessPoints(null, true)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_false_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.searchForAccessPoints(TEST_SSID, false)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_true_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.searchForAccessPoints(TEST_SSID, true)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_false() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); + + assertEquals(null, mWiseFy.searchForAccessPoints(TEST_SSID, false)); + } + + @Test + public void noCallbacks_failure_filterDuplicates_true() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); + + assertEquals(null, mWiseFy.searchForAccessPoints(TEST_SSID, true)); + } + + @Test + public void noCallbacks_success_filterDuplicates_false() { + List accessPoints = new ArrayList<>(); + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + accessPoints.add(accessPoint); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); + + assertEquals(accessPoints, mWiseFy.searchForAccessPoints(TEST_SSID, false)); + } + + @Test + public void noCallbacks_success_filterDuplicates_true() { + List accessPoints = new ArrayList<>(); + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + accessPoints.add(accessPoint); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); + + assertEquals(accessPoints, mWiseFy.searchForAccessPoints(TEST_SSID, true)); + } + + @Test + public void callbacks_failure_filterDuplicates_false_nullSSIDParam() { + SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); + mWiseFy.searchForAccessPoints(null, false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_filterDuplicates_false_nullSSIDParam_nullCallback() { + try { + mWiseFy.searchForAccessPoints(null, false, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_true_nullSSIDParam() { + SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); + mWiseFy.searchForAccessPoints(null, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_filterDuplicates_true_nullSSIDParam_nullCallback() { + try { + mWiseFy.searchForAccessPoints(null, true, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_false_missingPrerequisite() { + missingPrerequisite(); + SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); + mWiseFy.searchForAccessPoints(TEST_SSID, false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_filterDuplicates_false_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.searchForAccessPoints(TEST_SSID, false, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_true_missingPrerequisite() { + missingPrerequisite(); + SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); + mWiseFy.searchForAccessPoints(TEST_SSID, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForAccessPointsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_filterDuplicates_true_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.searchForAccessPoints(TEST_SSID, true, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_false() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); + + SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); + mWiseFy.searchForAccessPoints(TEST_SSID, false, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noAccessPointsFound(); + } + + @Test + public void callbacks_failure_filterDuplicates_false_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); + + try { + mWiseFy.searchForAccessPoints(TEST_SSID, false, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_filterDuplicates_true() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); + + SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); + mWiseFy.searchForAccessPoints(TEST_SSID, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noAccessPointsFound(); + } + + + @Test + public void callbacks_failure_filterDuplicates_true_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(null); + + try { + mWiseFy.searchForAccessPoints(TEST_SSID, true, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_filterDuplicates_false() { + List accessPoints = new ArrayList<>(); + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + accessPoints.add(accessPoint); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); + + SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); + mWiseFy.searchForAccessPoints(TEST_SSID, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).foundAccessPoints(accessPoints); + } + + @Test + public void callbacks_success_filterDuplicates_false_nullCallback() { + List accessPoints = new ArrayList<>(); + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + accessPoints.add(accessPoint); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); + + try { + mWiseFy.searchForAccessPoints(TEST_SSID, true, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success_filterDuplicates_true() { + List accessPoints = new ArrayList<>(); + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + accessPoints.add(accessPoint); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); + + SearchForAccessPointsCallbacks mockCallbacks = mock(SearchForAccessPointsCallbacks.class); + mWiseFy.searchForAccessPoints(TEST_SSID, true, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).foundAccessPoints(accessPoints); + } + + @Test + public void callbacks_success_filterDuplicates_true_nullCallback() { + List accessPoints = new ArrayList<>(); + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + accessPoints.add(accessPoint); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointsMatchingRegex(anyString(), anyBoolean())).thenReturn(accessPoints); + + try { + mWiseFy.searchForAccessPoints(TEST_SSID, true, null); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDTests.java index b1202443..947b92df 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDTests.java @@ -1,149 +1,144 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.fail; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.ArgumentMatchers.anyBoolean; -//import static org.mockito.ArgumentMatchers.anyInt; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class SearchForSSIDTests extends BaseTestClass { -// -// public SearchForSSIDTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_nullSSIDParam() { -// assertEquals(null, mWiseFy.searchForSSID(null, 1000)); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.searchForSSID(TEST_SSID, 1000)); -// } -// -// @Test -// public void noCallbacks_failure() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// assertEquals(null, mWiseFy.searchForSSID(TEST_SSID, 1000)); -// } -// -// @Test -// public void noCallbacks_success() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// assertEquals(TEST_SSID, mWiseFy.searchForSSID(TEST_SSID, 1000)); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam() { -// SearchForSSIDCallbacks mockCallbacks = mock(SearchForSSIDCallbacks.class); -// mWiseFy.searchForSSID(null, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForSSIDWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.searchForSSID(null, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// SearchForSSIDCallbacks mockCallbacks = mock(SearchForSSIDCallbacks.class); -// mWiseFy.searchForSSID(TEST_SSID, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForSSIDWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.searchForSSID(TEST_SSID, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// SearchForSSIDCallbacks mockCallbacks = mock(SearchForSSIDCallbacks.class); -// mWiseFy.searchForSSID(TEST_SSID, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).ssidNotFound(); -// } -// -// -// @Test -// public void callbacks_failure_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); -// -// try { -// mWiseFy.searchForSSID(TEST_SSID, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoint.level = -35; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// SearchForSSIDCallbacks mockCallbacks = mock(SearchForSSIDCallbacks.class); -// mWiseFy.searchForSSID(TEST_SSID, 1000, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).ssidFound(TEST_SSID); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); -// -// try { -// mWiseFy.searchForSSID(TEST_SSID, 1000, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class SearchForSSIDTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_nullSSIDParam() { + assertEquals(null, mWiseFy.searchForSSID(null, 1000)); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.searchForSSID(TEST_SSID, 1000)); + } + + @Test + public void noCallbacks_failure() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + assertEquals(null, mWiseFy.searchForSSID(TEST_SSID, 1000)); + } + + @Test + public void noCallbacks_success() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + assertEquals(TEST_SSID, mWiseFy.searchForSSID(TEST_SSID, 1000)); + } + + @Test + public void callbacks_failure_nullSSIDParam() { + SearchForSSIDCallbacks mockCallbacks = mock(SearchForSSIDCallbacks.class); + mWiseFy.searchForSSID(null, 1000, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForSSIDWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.searchForSSID(null, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + SearchForSSIDCallbacks mockCallbacks = mock(SearchForSSIDCallbacks.class); + mWiseFy.searchForSSID(TEST_SSID, 1000, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForSSIDWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.searchForSSID(TEST_SSID, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + SearchForSSIDCallbacks mockCallbacks = mock(SearchForSSIDCallbacks.class); + mWiseFy.searchForSSID(TEST_SSID, 1000, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).ssidNotFound(); + } + + + @Test + public void callbacks_failure_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(null); + + try { + mWiseFy.searchForSSID(TEST_SSID, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoint.level = -35; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + SearchForSSIDCallbacks mockCallbacks = mock(SearchForSSIDCallbacks.class); + mWiseFy.searchForSSID(TEST_SSID, 1000, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).ssidFound(TEST_SSID); + } + + @Test + public void callbacks_success_nullCallback() { + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findAccessPointByRegex(anyString(), anyInt(), anyBoolean())).thenReturn(accessPoint); + + try { + mWiseFy.searchForSSID(TEST_SSID, 1000, null); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDsTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDsTests.java index 07edf930..0e241871 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDsTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/SearchForSSIDsTests.java @@ -1,146 +1,141 @@ -//package com.isupatches.wisefy; -// -// -//import com.isupatches.wisefy.base.TestActivity; -//import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks; -//import com.isupatches.wisefy.constants.WiseFyCodes; -//import org.junit.Test; -//import java.util.ArrayList; -//import java.util.List; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static junit.framework.Assert.fail; -//import static org.junit.Assert.assertEquals; -//import static org.mockito.ArgumentMatchers.anyString; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.timeout; -//import static org.mockito.Mockito.verify; -//import static org.mockito.Mockito.when; -// -// -//public class SearchForSSIDsTests extends BaseTestClass { -// -// public SearchForSSIDsTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void noCallbacks_failure_nullSSIDParam() { -// assertEquals(null, mWiseFy.searchForSSIDs(null)); -// } -// -// @Test -// public void noCallbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// assertEquals(null, mWiseFy.searchForSSIDs(TEST_SSID)); -// } -// -// @Test -// public void noCallbacks_failure() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(null); -// -// assertEquals(null, mWiseFy.searchForSSIDs(TEST_SSID)); -// } -// -// @Test -// public void noCallbacks_success() { -// List ssids = new ArrayList<>(); -// ssids.add(TEST_SSID); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(ssids); -// -// assertEquals(ssids, mWiseFy.searchForSSIDs(TEST_SSID)); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam() { -// SearchForSSIDsCallbacks mockCallbacks = mock(SearchForSSIDsCallbacks.class); -// mWiseFy.searchForSSIDs(null, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForSSIDsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); -// } -// -// @Test -// public void callbacks_failure_nullSSIDParam_nullCallback() { -// try { -// mWiseFy.searchForSSIDs(null, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite() { -// missingPrerequisite(); -// SearchForSSIDsCallbacks mockCallbacks = mock(SearchForSSIDsCallbacks.class); -// mWiseFy.searchForSSIDs(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForSSIDsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); -// } -// -// @Test -// public void callbacks_failure_missingPrerequisite_nullCallback() { -// missingPrerequisite(); -// try { -// mWiseFy.searchForSSIDs(TEST_SSID, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_failure() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(null); -// -// SearchForSSIDsCallbacks mockCallbacks = mock(SearchForSSIDsCallbacks.class); -// mWiseFy.searchForSSIDs(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSSIDsFound(); -// } -// -// -// @Test -// public void callbacks_failure_nullCallback() { -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(null); -// -// try { -// mWiseFy.searchForSSIDs(TEST_SSID, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -// -// @Test -// public void callbacks_success() { -// List ssids = new ArrayList<>(); -// ssids.add(TEST_SSID); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(ssids); -// -// SearchForSSIDsCallbacks mockCallbacks = mock(SearchForSSIDsCallbacks.class); -// mWiseFy.searchForSSIDs(TEST_SSID, mockCallbacks); -// verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedSSIDs(ssids); -// } -// -// @Test -// public void callbacks_success_nullCallback() { -// List ssids = new ArrayList<>(); -// ssids.add(TEST_SSID); -// -// WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); -// mWiseFy.mWiseFySearch = mockWiseFySearch; -// when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(ssids); -// -// try { -// mWiseFy.searchForSSIDs(TEST_SSID, null); -// } catch (NullPointerException npe) { -// fail(); -// } -// } -//} +package com.isupatches.wisefy; + + +import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks; +import com.isupatches.wisefy.constants.WiseFyCodes; +import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static junit.framework.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + + +public class SearchForSSIDsTests extends BaseAndroidJUnit4TestClass { + + @Test + public void noCallbacks_failure_nullSSIDParam() { + assertEquals(null, mWiseFy.searchForSSIDs(null)); + } + + @Test + public void noCallbacks_failure_missingPrerequisite() { + missingPrerequisite(); + assertEquals(null, mWiseFy.searchForSSIDs(TEST_SSID)); + } + + @Test + public void noCallbacks_failure() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(null); + + assertEquals(null, mWiseFy.searchForSSIDs(TEST_SSID)); + } + + @Test + public void noCallbacks_success() { + List ssids = new ArrayList<>(); + ssids.add(TEST_SSID); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(ssids); + + assertEquals(ssids, mWiseFy.searchForSSIDs(TEST_SSID)); + } + + @Test + public void callbacks_failure_nullSSIDParam() { + SearchForSSIDsCallbacks mockCallbacks = mock(SearchForSSIDsCallbacks.class); + mWiseFy.searchForSSIDs(null, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForSSIDsWiseFyFailure(WiseFyCodes.MISSING_PARAMETER); + } + + @Test + public void callbacks_failure_nullSSIDParam_nullCallback() { + try { + mWiseFy.searchForSSIDs(null, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure_missingPrerequisite() { + missingPrerequisite(); + SearchForSSIDsCallbacks mockCallbacks = mock(SearchForSSIDsCallbacks.class); + mWiseFy.searchForSSIDs(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).searchForSSIDsWiseFyFailure(WiseFyCodes.MISSING_PREREQUISITE); + } + + @Test + public void callbacks_failure_missingPrerequisite_nullCallback() { + missingPrerequisite(); + try { + mWiseFy.searchForSSIDs(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_failure() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(null); + + SearchForSSIDsCallbacks mockCallbacks = mock(SearchForSSIDsCallbacks.class); + mWiseFy.searchForSSIDs(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).noSSIDsFound(); + } + + + @Test + public void callbacks_failure_nullCallback() { + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(null); + + try { + mWiseFy.searchForSSIDs(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } + + @Test + public void callbacks_success() { + List ssids = new ArrayList<>(); + ssids.add(TEST_SSID); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(ssids); + + SearchForSSIDsCallbacks mockCallbacks = mock(SearchForSSIDsCallbacks.class); + mWiseFy.searchForSSIDs(TEST_SSID, mockCallbacks); + verify(mockCallbacks, timeout(VERIFICATION_TIMEOUT)).retrievedSSIDs(ssids); + } + + @Test + public void callbacks_success_nullCallback() { + List ssids = new ArrayList<>(); + ssids.add(TEST_SSID); + + WiseFySearch mockWiseFySearch = mock(WiseFySearch.class); + mWiseFy.mWiseFySearch = mockWiseFySearch; + when(mockWiseFySearch.findSSIDsMatchingRegex(anyString())).thenReturn(ssids); + + try { + mWiseFy.searchForSSIDs(TEST_SSID, null); + } catch (NullPointerException npe) { + fail(); + } + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyConnectionTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyConnectionTests.java index 9d0d5889..e721eb62 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyConnectionTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyConnectionTests.java @@ -1,364 +1,359 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.NetworkInfo; -//import android.net.wifi.WifiInfo; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Before; -//import org.junit.Test; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; -//import static com.isupatches.wisefy.base.TestUtils.TEST_TYPE1; -//import static com.isupatches.wisefy.base.TestUtils.TEST_TYPE2; -//import static junit.framework.Assert.assertFalse; -//import static junit.framework.Assert.assertTrue; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class WiseFyConnectionTests extends BaseTestClass { -// -// public WiseFyConnectionTests() { -// super(TestActivity.class); -// } -// -// @Before -// public void setUp() { -// super.setUp(); -// WiseFyConnection.getInstance().mWiseFyPrerequisites.setWifiManager(mMockWiFiManager); -// WiseFyConnection.getInstance().mWiseFyPrerequisites.setConnectivityManager(mMockConnectivityManager); -// } -// -// /* -// * isCurrentNetworkConnectedToSSID tests -// */ -// -// @Test -// public void isCurrentNetworkConnectedToSSID_failure_nullSSIDParam() { -// assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(null)); -// } -// -// @Test -// public void isCurrentNetworkConnectedToSSID_failure_nullConnectionInfo() { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); -// } -// -// @Test -// public void isCurrentNetworkConnectedToSSID_failure_nullSSID() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(null); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(null)); -// } -// -// @Test -// public void isCurrentNetworkConnectedToSSID_failure_differentSSID() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID2); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); -// } -// -// @Test -// public void isCurrentNetworkConnectedToSSID_failure_notAvailable() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); -// } -// -// @Test -// public void isCurrentNetworkConnectedToSSID_failure_notAvailableOrConnected() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); -// } -// -// @Test -// public void isCurrentNetworkConnectedToSSID_failure_notConnected() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); -// } -// -// @Test -// public void isCurrentNetworkConnectedToSSID_success() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertTrue(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); -// } -// -// /* -// * isNetworkConnected tests -// */ -// -// @Test -// public void isNetworkConnected_failure_nullNetworkInfoParam() { -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnected(null)); -// } -// -// @Test -// public void isNetworkConnected_failure_notAvailable() { -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnected(networkInfo)); -// } -// -// @Test -// public void isNetworkConnected_failure_notAvailableOrConnected() { -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnected(networkInfo)); -// } -// -// @Test -// public void isNetworkConnected_failure_notConnected() { -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnected(networkInfo)); -// } -// -// @Test -// public void isNetworkConnected_success() { -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertTrue(WiseFyConnection.getInstance().isNetworkConnected(networkInfo)); -// } -// -// /* -// * isNetworkConnectedAndMatchesType tests -// */ -// -// @Test -// public void isNetworkConnectedAndMatchesType_failure_nullNetworkInfoParam() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(null, TEST_TYPE1)); -// } -// -// @Test -// public void isNetworkConnectedAndMatchesType_failure_notAvailable() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); -// } -// -// @Test -// public void isNetworkConnectedAndMatchesType_failure_notAvailableOrConnected() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); -// } -// -// @Test -// public void isNetworkConnectedAndMatchesType_failure_notConnected() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); -// } -// -// @Test -// public void isNetworkConnectedAndMatchesType_failure_nullTypeName() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(true); -// when(networkInfo.getTypeName()).thenReturn(null); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); -// } -// -// @Test -// public void isNetworkConnectedAndMatchesType_failure_differentTypeName() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(true); -// when(networkInfo.getTypeName()).thenReturn(TEST_TYPE2); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); -// } -// -// @Test -// public void isNetworkConnectedAndMatchesType_success() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(true); -// when(networkInfo.getTypeName()).thenReturn(TEST_TYPE1); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertTrue(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); -// } -// -// /* -// * waitToConnectToSSID tests -// */ -// -// @Test -// public void waitToConnectToSSID_failure_nullSSIDParam() { -// assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(null, 1000)); -// } -// -// @Test -// public void waitToConnectToSSID_failure_nullConnectionInfo() { -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); -// assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); -// } -// -// @Test -// public void waitToConnectToSSID_failure_nullSSID() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(null); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(null, 1000)); -// } -// -// @Test -// public void waitToConnectToSSID_failure_differentSSID() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID2); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); -// } -// -// @Test -// public void waitToConnectToSSID_failure_notAvailable() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); -// } -// -// @Test -// public void waitToConnectToSSID_failure_notAvailableOrConnected() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(false); -// when(networkInfo.isConnected()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); -// } -// -// @Test -// public void waitToConnectToSSID_failure_notConnected() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(false); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); -// } -// -// @Test -// public void waitToConnectToSSID_success() { -// WifiInfo currentNetwork = mock(WifiInfo.class); -// when(currentNetwork.getSSID()).thenReturn(TEST_SSID); -// when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); -// -// NetworkInfo networkInfo = mock(NetworkInfo.class); -// when(networkInfo.isAvailable()).thenReturn(true); -// when(networkInfo.isConnected()).thenReturn(true); -// when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); -// -// assertTrue(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import org.junit.Before; +import org.junit.Test; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; +import static com.isupatches.wisefy.base.TestUtils.TEST_TYPE1; +import static com.isupatches.wisefy.base.TestUtils.TEST_TYPE2; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class WiseFyConnectionTests extends BaseAndroidJUnit4TestClass { + + @Before + public void setUp() { + super.setUp(); + WiseFyConnection.getInstance().mWiseFyPrerequisites.setWifiManager(mMockWiFiManager); + WiseFyConnection.getInstance().mWiseFyPrerequisites.setConnectivityManager(mMockConnectivityManager); + } + + /* + * isCurrentNetworkConnectedToSSID tests + */ + + @Test + public void isCurrentNetworkConnectedToSSID_failure_nullSSIDParam() { + assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(null)); + } + + @Test + public void isCurrentNetworkConnectedToSSID_failure_nullConnectionInfo() { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); + } + + @Test + public void isCurrentNetworkConnectedToSSID_failure_nullSSID() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(null); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(null)); + } + + @Test + public void isCurrentNetworkConnectedToSSID_failure_differentSSID() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID2); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); + } + + @Test + public void isCurrentNetworkConnectedToSSID_failure_notAvailable() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); + } + + @Test + public void isCurrentNetworkConnectedToSSID_failure_notAvailableOrConnected() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); + } + + @Test + public void isCurrentNetworkConnectedToSSID_failure_notConnected() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); + } + + @Test + public void isCurrentNetworkConnectedToSSID_success() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertTrue(WiseFyConnection.getInstance().isCurrentNetworkConnectedToSSID(TEST_SSID)); + } + + /* + * isNetworkConnected tests + */ + + @Test + public void isNetworkConnected_failure_nullNetworkInfoParam() { + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnected(null)); + } + + @Test + public void isNetworkConnected_failure_notAvailable() { + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnected(networkInfo)); + } + + @Test + public void isNetworkConnected_failure_notAvailableOrConnected() { + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnected(networkInfo)); + } + + @Test + public void isNetworkConnected_failure_notConnected() { + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnected(networkInfo)); + } + + @Test + public void isNetworkConnected_success() { + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertTrue(WiseFyConnection.getInstance().isNetworkConnected(networkInfo)); + } + + /* + * isNetworkConnectedAndMatchesType tests + */ + + @Test + public void isNetworkConnectedAndMatchesType_failure_nullNetworkInfoParam() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(null, TEST_TYPE1)); + } + + @Test + public void isNetworkConnectedAndMatchesType_failure_notAvailable() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); + } + + @Test + public void isNetworkConnectedAndMatchesType_failure_notAvailableOrConnected() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); + } + + @Test + public void isNetworkConnectedAndMatchesType_failure_notConnected() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); + } + + @Test + public void isNetworkConnectedAndMatchesType_failure_nullTypeName() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(true); + when(networkInfo.getTypeName()).thenReturn(null); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); + } + + @Test + public void isNetworkConnectedAndMatchesType_failure_differentTypeName() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(true); + when(networkInfo.getTypeName()).thenReturn(TEST_TYPE2); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); + } + + @Test + public void isNetworkConnectedAndMatchesType_success() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(true); + when(networkInfo.getTypeName()).thenReturn(TEST_TYPE1); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertTrue(WiseFyConnection.getInstance().isNetworkConnectedAndMatchesType(networkInfo, TEST_TYPE1)); + } + + /* + * waitToConnectToSSID tests + */ + + @Test + public void waitToConnectToSSID_failure_nullSSIDParam() { + assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(null, 1000)); + } + + @Test + public void waitToConnectToSSID_failure_nullConnectionInfo() { + when(mMockWiFiManager.getConnectionInfo()).thenReturn(null); + assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); + } + + @Test + public void waitToConnectToSSID_failure_nullSSID() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(null); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(null, 1000)); + } + + @Test + public void waitToConnectToSSID_failure_differentSSID() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID2); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); + } + + @Test + public void waitToConnectToSSID_failure_notAvailable() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); + } + + @Test + public void waitToConnectToSSID_failure_notAvailableOrConnected() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(false); + when(networkInfo.isConnected()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); + } + + @Test + public void waitToConnectToSSID_failure_notConnected() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(false); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertFalse(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); + } + + @Test + public void waitToConnectToSSID_success() { + WifiInfo currentNetwork = mock(WifiInfo.class); + when(currentNetwork.getSSID()).thenReturn(TEST_SSID); + when(mMockWiFiManager.getConnectionInfo()).thenReturn(currentNetwork); + + NetworkInfo networkInfo = mock(NetworkInfo.class); + when(networkInfo.isAvailable()).thenReturn(true); + when(networkInfo.isConnected()).thenReturn(true); + when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); + + assertTrue(WiseFyConnection.getInstance().waitToConnectToSSID(TEST_SSID, 1000)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyPrerequisitesTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyPrerequisitesTests.java index 4aebf88f..f3f17a3d 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyPrerequisitesTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyPrerequisitesTests.java @@ -1,54 +1,49 @@ -//package com.isupatches.wisefy; -// -// -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static junit.framework.Assert.*; -// -// -//public class WiseFyPrerequisitesTests extends BaseTestClass { -// -// public WiseFyPrerequisitesTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void hasPrerequisites_nullWifiManager() { -// WiseFyPrerequisites.getInstance().setConnectivityManager(mMockConnectivityManager); -// WiseFyPrerequisites.getInstance().setWifiManager(null); -// assertFalse(WiseFyPrerequisites.getInstance().hasPrerequisites()); -// } -// -// @Test -// public void hasPrerequisites_nullConnectivityManager() { -// WiseFyPrerequisites.getInstance().setConnectivityManager(null); -// WiseFyPrerequisites.getInstance().setWifiManager(mMockWiFiManager); -// assertFalse(WiseFyPrerequisites.getInstance().hasPrerequisites()); -// } -// -// @Test -// public void hasPrerequisites_noManagers() { -// WiseFyPrerequisites.getInstance().setConnectivityManager(null); -// WiseFyPrerequisites.getInstance().setWifiManager(null); -// assertFalse(WiseFyPrerequisites.getInstance().hasPrerequisites()); -// } -// -// @Test -// public void hasPrerequisites_bothManagers() { -// WiseFyPrerequisites.getInstance().setConnectivityManager(mMockConnectivityManager); -// WiseFyPrerequisites.getInstance().setWifiManager(mMockWiFiManager); -// assertTrue(WiseFyPrerequisites.getInstance().hasPrerequisites()); -// } -// -// @Test -// public void connectivityManager_getterAndSetter() { -// WiseFyPrerequisites.getInstance().setConnectivityManager(mMockConnectivityManager); -// assertEquals(mMockConnectivityManager, WiseFyPrerequisites.getInstance().getConnectivityManager()); -// } -// -// @Test -// public void wifiManager_getterAndSetter() { -// WiseFyPrerequisites.getInstance().setWifiManager(mMockWiFiManager); -// assertEquals(mMockWiFiManager, WiseFyPrerequisites.getInstance().getWifiManager()); -// } -//} +package com.isupatches.wisefy; + + +import org.junit.Test; +import static junit.framework.Assert.*; + + +public class WiseFyPrerequisitesTests extends BaseAndroidJUnit4TestClass { + + @Test + public void hasPrerequisites_nullWifiManager() { + WiseFyPrerequisites.getInstance().setConnectivityManager(mMockConnectivityManager); + WiseFyPrerequisites.getInstance().setWifiManager(null); + assertFalse(WiseFyPrerequisites.getInstance().hasPrerequisites()); + } + + @Test + public void hasPrerequisites_nullConnectivityManager() { + WiseFyPrerequisites.getInstance().setConnectivityManager(null); + WiseFyPrerequisites.getInstance().setWifiManager(mMockWiFiManager); + assertFalse(WiseFyPrerequisites.getInstance().hasPrerequisites()); + } + + @Test + public void hasPrerequisites_noManagers() { + WiseFyPrerequisites.getInstance().setConnectivityManager(null); + WiseFyPrerequisites.getInstance().setWifiManager(null); + assertFalse(WiseFyPrerequisites.getInstance().hasPrerequisites()); + } + + @Test + public void hasPrerequisites_bothManagers() { + WiseFyPrerequisites.getInstance().setConnectivityManager(mMockConnectivityManager); + WiseFyPrerequisites.getInstance().setWifiManager(mMockWiFiManager); + assertTrue(WiseFyPrerequisites.getInstance().hasPrerequisites()); + } + + @Test + public void connectivityManager_getterAndSetter() { + WiseFyPrerequisites.getInstance().setConnectivityManager(mMockConnectivityManager); + assertEquals(mMockConnectivityManager, WiseFyPrerequisites.getInstance().getConnectivityManager()); + } + + @Test + public void wifiManager_getterAndSetter() { + WiseFyPrerequisites.getInstance().setWifiManager(mMockWiFiManager); + assertEquals(mMockWiFiManager, WiseFyPrerequisites.getInstance().getWifiManager()); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFySearchTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFySearchTests.java index a452837c..a69d045a 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFySearchTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFySearchTests.java @@ -1,860 +1,856 @@ -//package com.isupatches.wisefy; -// -// -//import android.net.wifi.ScanResult; -//import android.net.wifi.WifiConfiguration; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import java.util.ArrayList; -//import java.util.List; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; -//import static com.isupatches.wisefy.base.TestUtils.TEST_SSID3; -//import static junit.framework.Assert.assertEquals; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -// -//public class WiseFySearchTests extends BaseTestClass { -// -// public WiseFySearchTests() { -// super(TestActivity.class); -// } -// -// /* -// * findAccessPointByRegex tests -// */ -// -// @Test -// public void findAccessPointByRegex_failure_nullAccessPoints_takeHighest_false() { -// when(mMockWiFiManager.getScanResults()).thenReturn(null); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_nullAccessPoints_takeHighest_true() { -// when(mMockWiFiManager.getScanResults()).thenReturn(null); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_emptyAccessPointList_takeHighest_false() { -// when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_emptyAccessPointList_takeHighest_true() { -// when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_nullAccessPoint_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// accessPoints.add(null); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_nullAccessPoint_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// accessPoints.add(null); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_nullSSID_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint= mock(ScanResult.class); -// accessPoint.SSID = null; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_nullSSID_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint= mock(ScanResult.class); -// accessPoint.SSID = null; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_nonMatchingSSID_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint= mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID2; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_nonMatchingSSID_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint= mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID2; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_multipleNonMatchingSSIDs_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID2; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID3; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_failure_multipleNnonMatchingSSIDs_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1= mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID2; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID3; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void findAccessPointByRegex_success_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(accessPoint, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_success_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(accessPoint, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void findAccessPointByRegex_success_multipleSSIDs_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID2; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_success_multipleSSIDs_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID2; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// @Test -// public void findAccessPointByRegex_success_multipleSameSSIDs_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); -// } -// -// @Test -// public void findAccessPointByRegex_success_multipleSameSSIDs_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(accessPoint2, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); -// } -// -// /* -// * findAccessPointsMatchingRegex tests -// */ -// -// @Test -// public void findAccessPointsMatchingRegex_failure_nullAccessPoints_takeHighest_false() { -// when(mMockWiFiManager.getScanResults()).thenReturn(null); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_nullAccessPoints_takeHighest_true() { -// when(mMockWiFiManager.getScanResults()).thenReturn(null); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_emptyAccessPointList_takeHighest_false() { -// when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_emptyAccessPointList_takeHighest_true() { -// when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_nullAccessPoint_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// accessPoints.add(null); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_nullAccessPoint_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// accessPoints.add(null); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_nullSSID_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint= mock(ScanResult.class); -// accessPoint.SSID = null; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_nullSSID_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint= mock(ScanResult.class); -// accessPoint.SSID = null; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_nonMatchingSSID_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint= mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID2; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_nonMatchingSSID_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint= mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID2; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_multipleNonMatchingSSIDs_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID2; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID3; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_failure_multipleNnonMatchingSSIDs_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1= mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID2; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID3; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_success_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(accessPoints, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_success_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(accessPoints, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_success_multipleSSIDs_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// expectedResults.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID2; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_success_multipleSSIDs_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// expectedResults.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID2; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_success_multipleSameSSIDs_takeHighest_false() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// expectedResults.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// expectedResults.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); -// } -// -// @Test -// public void findAccessPointsMatchingRegex_success_multipleSameSSIDs_takeHighest_true() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// expectedResults.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); -// } -// -// /* -// * findSavedNetworkByRegex tests -// */ -// -// @Test -// public void findSavedNetworkByRegex_failure_nullSavedNetworkList() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworkByRegex_failure_emptySavedNetworkList() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworkByRegex_failure_nullWifiConfiguration() { -// List wifiList = new ArrayList<>(); -// wifiList.add(null); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworkByRegex_failure_nullSSID() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = null; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworkByRegex_failure_nonMatchingSSID() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworkByRegex_failure_multipleNonMatchingSSIDs() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); -// mWiFiConfiguration1.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration1); -// -// WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); -// mWiFiConfiguration2.SSID = TEST_SSID3; -// wifiList.add(mWiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworkByRegex_success() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(mWiFiConfiguration, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworkByRegex_success_multipleSSIDs() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); -// mWiFiConfiguration1.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration1); -// -// WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); -// mWiFiConfiguration2.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(mWiFiConfiguration1, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); -// } -// -// /* -// * findSavedNetworksMatchingRegex tests -// */ -// -// @Test -// public void findSavedNetworksMatchingRegex_failure_nullSavedNetworkList() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_failure_emptySavedNetworkList() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_failure_nullWifiConfiguration() { -// List wifiList = new ArrayList<>(); -// wifiList.add(null); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_failure_nullSSID() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = null; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_failure_nonMatchingSSID() { -// List wifiList = new ArrayList<>(); -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_failure_multipleNonMatchingSSIDs() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); -// mWiFiConfiguration1.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration1); -// -// WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); -// mWiFiConfiguration2.SSID = TEST_SSID3; -// wifiList.add(mWiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_success() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(wifiList, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSavedNetworksMatchingRegex_success_multipleSSIDs() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); -// mWiFiConfiguration1.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration1); -// -// WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); -// mWiFiConfiguration2.SSID = TEST_SSID2; -// wifiList.add(mWiFiConfiguration2); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(wifiList, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(".*Test.*")); -// } -// -// /* -// * findSSIDsMatchingRegex tests -// */ -// -// @Test -// public void findSSIDsMatchingRegex_failure_nullAccessPoints() { -// when(mMockWiFiManager.getScanResults()).thenReturn(null); -// assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSSIDsMatchingRegex_failure_emptySavedNetworkList() { -// when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); -// assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSSIDsMatchingRegex_failure_nullWifiConfiguration() { -// List accessPoints = new ArrayList<>(); -// accessPoints.add(null); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSSIDsMatchingRegex_failure_nullSSID() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = null; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSSIDsMatchingRegex_failure_nonMatchingSSID() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID2; -// accessPoints.add(accessPoint); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSSIDsMatchingRegex_failure_multipleNonMatchingSSIDs() { -// List accessPoints = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID2; -// accessPoints.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID3; -// accessPoints.add(accessPoint2); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSSIDsMatchingRegex_success() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint = mock(ScanResult.class); -// accessPoint.SSID = TEST_SSID; -// accessPoints.add(accessPoint); -// expectedResults.add(TEST_SSID); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(expectedResults, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); -// } -// -// @Test -// public void findSSIDsMatchingRegex_success_multipleSSIDs() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoints.add(accessPoint1); -// expectedResults.add(TEST_SSID); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID; -// accessPoints.add(accessPoint2); -// expectedResults.add(TEST_SSID); -// -// when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); -// assertEquals(expectedResults, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(".*Test.*")); -// } -// -// /* -// * isNetworkASavedConfiguration tests -// */ -// -// @Test -// public void isNetworkASavedConfiguration_failure() { -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); -// assertEquals(false, mWiseFy.mWiseFySearch.isNetworkASavedConfiguration(TEST_SSID)); -// } -// -// @Test -// public void isNetworkASavedConfiguration_success() { -// List wifiList = new ArrayList<>(); -// -// WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); -// mWiFiConfiguration.SSID = TEST_SSID; -// wifiList.add(mWiFiConfiguration); -// -// when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); -// assertEquals(true, mWiseFy.mWiseFySearch.isNetworkASavedConfiguration(TEST_SSID)); -// } -// -// /* -// * removeEntriesWithLowerSignalStrength tests -// */ -// -// @Test -// public void removeEntriesWithLowerSignalStrength_differentSSIDs() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// expectedResults.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID2; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// expectedResults.add(accessPoint2); -// -// assertEquals(expectedResults, mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); -// } -// -// @Test -// public void removeEntriesWithLowerSignalStrength_sameSignalLevels() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -70; -// accessPoints.add(accessPoint1); -// expectedResults.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID; -// accessPoint2.level = -70; -// accessPoints.add(accessPoint2); -// -// assertEquals(expectedResults, mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); -// } -// -// @Test -// public void removeEntriesWithLowerSignalStrength_accessPoint1Higher() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoint1.level = -50; -// accessPoints.add(accessPoint1); -// expectedResults.add(accessPoint1); -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID; -// accessPoint2.level = -70; -// accessPoints.add(accessPoint2); -// -// assertEquals(expectedResults , mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); -// } -// -// @Test -// public void removeEntriesWithLowerSignalStrength_accessPoint2Higher() { -// List accessPoints = new ArrayList<>(); -// List expectedResults = new ArrayList<>(); -// -// ScanResult accessPoint1 = mock(ScanResult.class); -// accessPoint1.SSID = TEST_SSID; -// accessPoints.add(accessPoint1); -// accessPoint1.level = -70; -// -// ScanResult accessPoint2 = mock(ScanResult.class); -// accessPoint2.SSID = TEST_SSID; -// accessPoint2.level = -50; -// accessPoints.add(accessPoint2); -// expectedResults.add(accessPoint2); -// -// assertEquals(expectedResults , mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); -// } -//} +package com.isupatches.wisefy; + + +import android.net.wifi.ScanResult; +import android.net.wifi.WifiConfiguration; +import org.junit.Test; +import java.util.ArrayList; +import java.util.List; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID2; +import static com.isupatches.wisefy.base.TestUtils.TEST_SSID3; +import static junit.framework.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class WiseFySearchTests extends BaseAndroidJUnit4TestClass { + + + /* + * findAccessPointByRegex tests + */ + + @Test + public void findAccessPointByRegex_failure_nullAccessPoints_takeHighest_false() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_nullAccessPoints_takeHighest_true() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_emptyAccessPointList_takeHighest_false() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_emptyAccessPointList_takeHighest_true() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_nullAccessPoint_takeHighest_false() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_nullAccessPoint_takeHighest_true() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_nullSSID_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_nullSSID_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_nonMatchingSSID_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_nonMatchingSSID_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_failure_multipleNonMatchingSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_failure_multipleNnonMatchingSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1= mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_success_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_success_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_success_multipleSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_success_multipleSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + @Test + public void findAccessPointByRegex_success_multipleSameSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint1, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, false)); + } + + @Test + public void findAccessPointByRegex_success_multipleSameSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoint2, mWiseFy.mWiseFySearch.findAccessPointByRegex(TEST_SSID, 1000, true)); + } + + /* + * findAccessPointsMatchingRegex tests + */ + + @Test + public void findAccessPointsMatchingRegex_failure_nullAccessPoints_takeHighest_false() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullAccessPoints_takeHighest_true() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_emptyAccessPointList_takeHighest_false() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_emptyAccessPointList_takeHighest_true() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullAccessPoint_takeHighest_false() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullAccessPoint_takeHighest_true() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullSSID_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nullSSID_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nonMatchingSSID_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_nonMatchingSSID_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint= mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_multipleNonMatchingSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_failure_multipleNnonMatchingSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1= mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_success_takeHighest_false() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoints, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_success_takeHighest_true() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(accessPoints, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_success_multipleSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_success_multipleSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + @Test + public void findAccessPointsMatchingRegex_success_multipleSameSSIDs_takeHighest_false() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + expectedResults.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, false)); + } + + @Test + public void findAccessPointsMatchingRegex_success_multipleSameSSIDs_takeHighest_true() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + expectedResults.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findAccessPointsMatchingRegex(TEST_SSID, true)); + } + + /* + * findSavedNetworkByRegex tests + */ + + @Test + public void findSavedNetworkByRegex_failure_nullSavedNetworkList() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworkByRegex_failure_emptySavedNetworkList() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworkByRegex_failure_nullWifiConfiguration() { + List wifiList = new ArrayList<>(); + wifiList.add(null); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworkByRegex_failure_nullSSID() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = null; + wifiList.add(mWiFiConfiguration); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworkByRegex_failure_nonMatchingSSID() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID2; + wifiList.add(mWiFiConfiguration); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworkByRegex_failure_multipleNonMatchingSSIDs() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); + mWiFiConfiguration1.SSID = TEST_SSID2; + wifiList.add(mWiFiConfiguration1); + + WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); + mWiFiConfiguration2.SSID = TEST_SSID3; + wifiList.add(mWiFiConfiguration2); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworkByRegex_success() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(mWiFiConfiguration, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworkByRegex_success_multipleSSIDs() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); + mWiFiConfiguration1.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration1); + + WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); + mWiFiConfiguration2.SSID = TEST_SSID2; + wifiList.add(mWiFiConfiguration2); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(mWiFiConfiguration1, mWiseFy.mWiseFySearch.findSavedNetworkByRegex(TEST_SSID)); + } + + /* + * findSavedNetworksMatchingRegex tests + */ + + @Test + public void findSavedNetworksMatchingRegex_failure_nullSavedNetworkList() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworksMatchingRegex_failure_emptySavedNetworkList() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworksMatchingRegex_failure_nullWifiConfiguration() { + List wifiList = new ArrayList<>(); + wifiList.add(null); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworksMatchingRegex_failure_nullSSID() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = null; + wifiList.add(mWiFiConfiguration); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworksMatchingRegex_failure_nonMatchingSSID() { + List wifiList = new ArrayList<>(); + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID2; + wifiList.add(mWiFiConfiguration); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworksMatchingRegex_failure_multipleNonMatchingSSIDs() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); + mWiFiConfiguration1.SSID = TEST_SSID2; + wifiList.add(mWiFiConfiguration1); + + WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); + mWiFiConfiguration2.SSID = TEST_SSID3; + wifiList.add(mWiFiConfiguration2); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(null, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworksMatchingRegex_success() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(wifiList, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(TEST_SSID)); + } + + @Test + public void findSavedNetworksMatchingRegex_success_multipleSSIDs() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration1 = new WifiConfiguration(); + mWiFiConfiguration1.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration1); + + WifiConfiguration mWiFiConfiguration2 = new WifiConfiguration(); + mWiFiConfiguration2.SSID = TEST_SSID2; + wifiList.add(mWiFiConfiguration2); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(wifiList, mWiseFy.mWiseFySearch.findSavedNetworksMatchingRegex(".*Test.*")); + } + + /* + * findSSIDsMatchingRegex tests + */ + + @Test + public void findSSIDsMatchingRegex_failure_nullAccessPoints() { + when(mMockWiFiManager.getScanResults()).thenReturn(null); + assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_failure_emptySavedNetworkList() { + when(mMockWiFiManager.getScanResults()).thenReturn(new ArrayList()); + assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_failure_nullWifiConfiguration() { + List accessPoints = new ArrayList<>(); + accessPoints.add(null); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_failure_nullSSID() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = null; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_failure_nonMatchingSSID() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID2; + accessPoints.add(accessPoint); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_failure_multipleNonMatchingSSIDs() { + List accessPoints = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID2; + accessPoints.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID3; + accessPoints.add(accessPoint2); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(null, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_success() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint = mock(ScanResult.class); + accessPoint.SSID = TEST_SSID; + accessPoints.add(accessPoint); + expectedResults.add(TEST_SSID); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(TEST_SSID)); + } + + @Test + public void findSSIDsMatchingRegex_success_multipleSSIDs() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoints.add(accessPoint1); + expectedResults.add(TEST_SSID); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoints.add(accessPoint2); + expectedResults.add(TEST_SSID); + + when(mMockWiFiManager.getScanResults()).thenReturn(accessPoints); + assertEquals(expectedResults, mWiseFy.mWiseFySearch.findSSIDsMatchingRegex(".*Test.*")); + } + + /* + * isNetworkASavedConfiguration tests + */ + + @Test + public void isNetworkASavedConfiguration_failure() { + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList()); + assertEquals(false, mWiseFy.mWiseFySearch.isNetworkASavedConfiguration(TEST_SSID)); + } + + @Test + public void isNetworkASavedConfiguration_success() { + List wifiList = new ArrayList<>(); + + WifiConfiguration mWiFiConfiguration = new WifiConfiguration(); + mWiFiConfiguration.SSID = TEST_SSID; + wifiList.add(mWiFiConfiguration); + + when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList); + assertEquals(true, mWiseFy.mWiseFySearch.isNetworkASavedConfiguration(TEST_SSID)); + } + + /* + * removeEntriesWithLowerSignalStrength tests + */ + + @Test + public void removeEntriesWithLowerSignalStrength_differentSSIDs() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID2; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + expectedResults.add(accessPoint2); + + assertEquals(expectedResults, mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); + } + + @Test + public void removeEntriesWithLowerSignalStrength_sameSignalLevels() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -70; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -70; + accessPoints.add(accessPoint2); + + assertEquals(expectedResults, mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); + } + + @Test + public void removeEntriesWithLowerSignalStrength_accessPoint1Higher() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoint1.level = -50; + accessPoints.add(accessPoint1); + expectedResults.add(accessPoint1); + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -70; + accessPoints.add(accessPoint2); + + assertEquals(expectedResults , mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); + } + + @Test + public void removeEntriesWithLowerSignalStrength_accessPoint2Higher() { + List accessPoints = new ArrayList<>(); + List expectedResults = new ArrayList<>(); + + ScanResult accessPoint1 = mock(ScanResult.class); + accessPoint1.SSID = TEST_SSID; + accessPoints.add(accessPoint1); + accessPoint1.level = -70; + + ScanResult accessPoint2 = mock(ScanResult.class); + accessPoint2.SSID = TEST_SSID; + accessPoint2.level = -50; + accessPoints.add(accessPoint2); + expectedResults.add(accessPoint2); + + assertEquals(expectedResults , mWiseFy.mWiseFySearch.removeEntriesWithLowerSignalStrength(accessPoints)); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.java index e7892ecb..a1acaabb 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTests.java @@ -1,47 +1,44 @@ -//package com.isupatches.wisefy; -// -// -//import com.google.android.gms.iid.InstanceID; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Test; -//import static org.junit.Assert.*; -// -// -//public class WiseFyTests extends BaseTestClass { -// -// public WiseFyTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void builder_loggingFalse() { -// WiseFy wiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(false).getSmarts(); -// assertEquals(false, wiseFy.mWiseFyConfiguration.isLoggingEnabled()); -// assertEquals(false, wiseFy.isLoggingEnabled()); -// } -// -// @Test -// public void builder_loggingTrue() { -// WiseFy wiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(true).getSmarts(); -// assertEquals(true, wiseFy.mWiseFyConfiguration.isLoggingEnabled()); -// assertEquals(true, wiseFy.isLoggingEnabled()); -// } -// -// @Test -// public void calculateBars() { -// int result = mWiseFy.calculateBars(-35, 5); -// assertEquals(4, result); -// } -// -// @Test -// public void compareSignalLevel() { -// int result = mWiseFy.compareSignalLevel(-35, -70); -// assertEquals(35, result); -// } -// -// @Test -// public void olderGcm_IllegalAccessError_notThrown() { -// InstanceID instanceID = InstanceID.getInstance(mActivityTestRule.getActivity()); -// assertNotNull(instanceID); -// } -//} \ No newline at end of file +package com.isupatches.wisefy; + + +import android.support.test.InstrumentationRegistry; + +import com.google.android.gms.iid.InstanceID; +import org.junit.Test; +import static org.junit.Assert.*; + + +public class WiseFyTests extends BaseAndroidJUnit4TestClass { + + @Test + public void builder_loggingFalse() { + WiseFy wiseFy = new WiseFy.brains(InstrumentationRegistry.getContext()).logging(false).getSmarts(); + assertEquals(false, wiseFy.mWiseFyConfiguration.isLoggingEnabled()); + assertEquals(false, wiseFy.isLoggingEnabled()); + } + + @Test + public void builder_loggingTrue() { + WiseFy wiseFy = new WiseFy.brains(InstrumentationRegistry.getContext()).logging(true).getSmarts(); + assertEquals(true, wiseFy.mWiseFyConfiguration.isLoggingEnabled()); + assertEquals(true, wiseFy.isLoggingEnabled()); + } + + @Test + public void calculateBars() { + int result = mWiseFy.calculateBars(-35, 5); + assertEquals(4, result); + } + + @Test + public void compareSignalLevel() { + int result = mWiseFy.compareSignalLevel(-35, -70); + assertEquals(35, result); + } + + @Test + public void olderGcm_IllegalAccessError_notThrown() { + InstanceID instanceID = InstanceID.getInstance(InstrumentationRegistry.getContext()); + assertNotNull(instanceID); + } +} \ No newline at end of file diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/test/BuilderTests.java b/wisefy/src/androidTest/java/com/isupatches/wisefy/test/BuilderTests.java index e829d4e8..041e3edf 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/test/BuilderTests.java +++ b/wisefy/src/androidTest/java/com/isupatches/wisefy/test/BuilderTests.java @@ -1,32 +1,23 @@ -//package com.isupatches.wisefy.test; -// -// -//import android.support.test.rule.ActivityTestRule; -//import com.isupatches.wisefy.WiseFy; -//import com.isupatches.wisefy.base.TestActivity; -//import org.junit.Rule; -//import org.junit.Test; -//import static org.junit.Assert.assertEquals; -// -// -//public class BuilderTests extends ActivityTestRule { -// -// @Rule -// public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(TestActivity.class); -// -// public BuilderTests() { -// super(TestActivity.class); -// } -// -// @Test -// public void builder_loggingFalse() { -// WiseFy wiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(false).getSmarts(); -// assertEquals(false, wiseFy.isLoggingEnabled()); -// } -// -// @Test -// public void builder_loggingTrue() { -// WiseFy wiseFy = new WiseFy.brains(mActivityTestRule.getActivity()).logging(true).getSmarts(); -// assertEquals(true, wiseFy.isLoggingEnabled()); -// } -//} +package com.isupatches.wisefy.test; + + +import android.support.test.InstrumentationRegistry; +import com.isupatches.wisefy.WiseFy; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + + +public class BuilderTests { + + @Test + public void builder_loggingFalse() { + WiseFy wiseFy = new WiseFy.brains(InstrumentationRegistry.getContext()).logging(false).getSmarts(); + assertEquals(false, wiseFy.isLoggingEnabled()); + } + + @Test + public void builder_loggingTrue() { + WiseFy wiseFy = new WiseFy.brains(InstrumentationRegistry.getContext()).logging(true).getSmarts(); + assertEquals(true, wiseFy.isLoggingEnabled()); + } +} diff --git a/wisefy/src/androidTest/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java b/wisefy/src/test/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java similarity index 97% rename from wisefy/src/androidTest/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java rename to wisefy/src/test/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java index 19bccbeb..5ea07b6b 100644 --- a/wisefy/src/androidTest/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java +++ b/wisefy/src/test/java/com/isupatches/wisefy/test/PublicApiVisibilityTests.java @@ -1,13 +1,10 @@ package com.isupatches.wisefy.test; -import android.content.Intent; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; -import android.support.test.rule.ActivityTestRule; import com.isupatches.wisefy.WiseFy; -import com.isupatches.wisefy.base.TestActivity; import com.isupatches.wisefy.callbacks.AddOpenNetworkCallbacks; import com.isupatches.wisefy.callbacks.AddWEPNetworkCallbacks; import com.isupatches.wisefy.callbacks.AddWPA2NetworkCallbacks; @@ -27,7 +24,6 @@ import com.isupatches.wisefy.callbacks.SearchForSSIDCallbacks; import com.isupatches.wisefy.callbacks.SearchForSSIDsCallbacks; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import java.util.List; import static junit.framework.Assert.assertEquals; @@ -39,21 +35,12 @@ import static org.mockito.Mockito.verify; -public class PublicApiVisibilityTests extends ActivityTestRule { - - @Rule - public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(TestActivity.class); +public class PublicApiVisibilityTests { private WiseFy mWiseFy; - public PublicApiVisibilityTests() { - super(TestActivity.class); - } - @Before public void setUp() { - mActivityTestRule.launchActivity(new Intent()); - mWiseFy = mock(WiseFy.class); }