Skip to content

Commit

Permalink
Add more tests, switch to String.format, update more libs, and restor…
Browse files Browse the repository at this point in the history
…e travis-ci functionality
  • Loading branch information
isuPatches committed Jul 2, 2017
1 parent 2cb4425 commit db218ba
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 68 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.3'
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1'
classpath "com.github.dcendents:android-maven-gradle-plugin:1.5"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath "org.jacoco:org.jacoco.core:0.7.8"
Expand Down
226 changes: 207 additions & 19 deletions wisefy/src/androidTest/java/com/isupatches/wisefy/WiseFyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void addOpenNetwork_failure() {
when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE);
int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID);
assertEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
assertEquals(1, 2);
}

@Test
Expand All @@ -77,6 +76,25 @@ public void addOpenNetwork_success() {
assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
}

@Test
public void addOpenNetwork_success_alreadyConfigured() {
setManagers();

List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
mWiFiConfiguration.SSID = OPEN_NETWORK_SSID;
wifiList.add(mWiFiConfiguration);

WifiInfo mockWiFiInfo = mock(WifiInfo.class);
when(mockWiFiInfo.getSSID()).thenReturn(OPEN_NETWORK_SSID);

when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWiFiInfo);

int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID);
assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
}

@Test
public void addWEPNetwork_failure() {
setManagers();
Expand Down Expand Up @@ -112,6 +130,24 @@ public void addWEPNetwork_success() {
assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
}

@Test
public void addWEPNetwork_success_alreadyConfigured() {
setManagers();
List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
mWiFiConfiguration.SSID = WEP_NETWORK_SSID;
wifiList.add(mWiFiConfiguration);

WifiInfo mockWiFiInfo = mock(WifiInfo.class);
when(mockWiFiInfo.getSSID()).thenReturn(WEP_NETWORK_SSID);

when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWiFiInfo);

int result = mWiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD);
assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
}

@Test
public void addWPA2Network_failure() {
when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE);
Expand Down Expand Up @@ -146,6 +182,26 @@ public void addWPA2Network_success() {
assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
}

@Test
public void addWPA2Network_success_alreadyConfigured() {
setManagers();

setManagers();
List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
mWiFiConfiguration.SSID = WPA2_NETWORK_SSID;
wifiList.add(mWiFiConfiguration);

WifiInfo mockWiFiInfo = mock(WifiInfo.class);
when(mockWiFiInfo.getSSID()).thenReturn(WPA2_NETWORK_SSID);

when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWiFiInfo);

int result = mWiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD);
assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
}

@Test
public void builder_loggingFalse() {
WiseFy wiseFy = new WiseFy.withContext(mActivityTestRule.getActivity()).logging(false).getSmarts();
Expand All @@ -171,8 +227,9 @@ public void compareSignalLevel() {
}

@Test
public void connectToNetwork_failure_noList() {
public void connectToNetwork_failure_emptyList() {
setManagers();
when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(new ArrayList<WifiConfiguration>());
boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1);
assertEquals(false, result);
}
Expand Down Expand Up @@ -225,6 +282,14 @@ public void connectToNetwork_failure_notConnected() {
assertEquals(false, result);
}

@Test
public void connectToNetwork_failure_nullList() {
setManagers();
when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(null);
boolean result = mWiseFy.connectToNetwork(TEST_SSID, 1);
assertEquals(false, result);
}

@Test
public void connectToNetwork_failure_nullWifiManager() {
setManagersToNull();
Expand Down Expand Up @@ -362,10 +427,10 @@ public void getFrequency_currentNetwork_success() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setManagers();
WifiInfo mockWifiInfo = mock(WifiInfo.class);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo);

assertEquals(TEST_NETWORK_FREQUENCY, mWiseFy.getFrequency());
assertEquals(TEST_NETWORK_FREQUENCY_24GHZ, mWiseFy.getFrequency());
}
}

Expand All @@ -381,10 +446,10 @@ public void getFrequency_provideWifiInfo_success() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setManagers();
WifiInfo mockWifiInfo = mock(WifiInfo.class);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_24GHZ);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo);

assertEquals(TEST_NETWORK_FREQUENCY, mWiseFy.getFrequency(mockWifiInfo));
assertEquals(TEST_NETWORK_FREQUENCY_24GHZ, mWiseFy.getFrequency(mockWifiInfo));
}
}

Expand Down Expand Up @@ -536,7 +601,16 @@ public void isDeviceConnectedToMobileNetwork_failure_notConnected() {

@Test
public void isDeviceConnectedToMobileNetwork_failure_nullConfigurationManager() {
setManagersToNull();
setManagers();
setConnectivityManagerToNull();
boolean result = mWiseFy.isDeviceConnectedToMobileNetwork();
assertEquals(false, result);
}

@Test
public void isDeviceConnectedToMobileNetwork_failure_nullActiveNetworkInfo() {
setManagers();
when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(null);
boolean result = mWiseFy.isDeviceConnectedToMobileNetwork();
assertEquals(false, result);
}
Expand Down Expand Up @@ -685,7 +759,7 @@ public void isDeviceConnectedToSSID_failure_differentSSID() {
}

@Test
public void isDeviceConnectedToSSID_failure_NotAvailable() {
public void isDeviceConnectedToSSID_failure_notAvailable() {
setManagers();
List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
Expand All @@ -709,7 +783,7 @@ public void isDeviceConnectedToSSID_failure_NotAvailable() {
}

@Test
public void isDeviceConnectedToSSID_failure_NotConnected() {
public void isDeviceConnectedToSSID_failure_notConnected() {
setManagers();
List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
Expand All @@ -733,7 +807,79 @@ public void isDeviceConnectedToSSID_failure_NotConnected() {
}

@Test
public void isDeviceConnectedToSSID_failure_NullWifiManager() {
public void isDeviceConnectedToSSID_failure_nullActiveNetworkInfo() {
setManagers();
List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
mWiFiConfiguration.SSID = TEST_SSID;
wifiList.add(mWiFiConfiguration);

WifiInfo mockWiFiInfo = mock(WifiInfo.class);
when(mockWiFiInfo.getSSID()).thenReturn(TEST_SSID);

when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWiFiInfo);
when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(null);

boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID);
assertEquals(false, result);
}

@Test
public void isDeviceConnectedToSSID_failure_nullConnectionInfo() {
setManagers();
List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
mWiFiConfiguration.SSID = TEST_SSID;
wifiList.add(mWiFiConfiguration);

when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(null);

boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID);
assertEquals(false, result);
}

@Test
public void isDeviceConnectedToSSID_failure_nullConnectionInfoSSID() {
setManagers();
List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
mWiFiConfiguration.SSID = TEST_SSID;
wifiList.add(mWiFiConfiguration);

WifiInfo mockWiFiInfo = mock(WifiInfo.class);
when(mockWiFiInfo.getSSID()).thenReturn(null);

when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWiFiInfo);

boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID);
assertEquals(false, result);
}

@Test
public void isDeviceConnectedToSSID_failure_nullConnectivityManagerManager() {
setManagers();
setConnectivityManagerToNull();

List<WifiConfiguration> wifiList = new ArrayList<>();
WifiConfiguration mWiFiConfiguration = new WifiConfiguration();
mWiFiConfiguration.SSID = TEST_SSID;
wifiList.add(mWiFiConfiguration);

WifiInfo mockWiFiInfo = mock(WifiInfo.class);
when(mockWiFiInfo.getSSID()).thenReturn(TEST_SSID);

when(mMockWiFiManager.getConfiguredNetworks()).thenReturn(wifiList);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWiFiInfo);

boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID);
assertEquals(false, result);
}

@Test
public void isDeviceConnectedToSSID_failure_nullWifiManager() {
setManagersToNull();
boolean result = mWiseFy.isDeviceConnectedToSSID(TEST_SSID);
assertEquals(false, result);
Expand Down Expand Up @@ -791,9 +937,18 @@ public void isDeviceConnectedToWifiNetwork_failure_notConnected() {
assertEquals(false, result);
}

@Test
public void isDeviceConnectedToWifiNetwork_failure_nullActiveNetworkInfo() {
setManagers();
when(mMockConnectivityManager.getActiveNetworkInfo()).thenReturn(null);
boolean result = mWiseFy.isDeviceConnectedToWifiNetwork();
assertEquals(false, result);
}

@Test
public void isDeviceConnectedToWifiNetwork_failure_nullConfigurationManager() {
setManagersToNull();
setManagers();
setConnectivityManagerToNull();
boolean result = mWiseFy.isDeviceConnectedToWifiNetwork();
assertEquals(false, result);
}
Expand All @@ -813,7 +968,7 @@ public void isDeviceConnectedToWifiNetwork_failure_wrongType() {
}

@Test
public void isDeviceConnectedToWifiNetwork_Success() {
public void isDeviceConnectedToWifiNetwork_success() {
setManagers();
NetworkInfo mockNetworkInfo = mock(NetworkInfo.class);
when(mockNetworkInfo.getTypeName()).thenReturn("WIFI");
Expand All @@ -827,11 +982,23 @@ public void isDeviceConnectedToWifiNetwork_Success() {
}

@Test
public void isNetwork5gHz_currentNetwork_failure() {
public void isNetwork5gHz_currentNetwork_failure_above5ghz() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setManagers();
WifiInfo mockWifiInfo = mock(WifiInfo.class);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo);

assertEquals(false, mWiseFy.isNetwork5gHz());
}
}

@Test
public void isNetwork5gHz_currentNetwork_failure_below5ghz() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setManagers();
WifiInfo mockWifiInfo = mock(WifiInfo.class);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo);

assertEquals(false, mWiseFy.isNetwork5gHz());
Expand All @@ -843,19 +1010,31 @@ public void isNetwork5gHz_currentNetwork_success() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setManagers();
WifiInfo mockWifiInfo = mock(WifiInfo.class);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5G);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo);

assertEquals(true, mWiseFy.isNetwork5gHz());
}
}

@Test
public void isNetwork5gHz_provideWifiInfo_failure() {
public void isNetwork5gHz_provideWifiInfo_failure_above5ghz() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setManagers();
WifiInfo mockWifiInfo = mock(WifiInfo.class);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_ABOVE_5GHZ);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo);

assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo));
}
}

@Test
public void isNetwork5gHz_provideWifiInfo_failure_below5ghz() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setManagers();
WifiInfo mockWifiInfo = mock(WifiInfo.class);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_BELOW_5GHZ);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo);

assertEquals(false, mWiseFy.isNetwork5gHz(mockWifiInfo));
Expand All @@ -867,7 +1046,7 @@ public void isNetwork5gHz_provideWifiInfo_success() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setManagers();
WifiInfo mockWifiInfo = mock(WifiInfo.class);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5G);
when(mockWifiInfo.getFrequency()).thenReturn(TEST_NETWORK_FREQUENCY_5GHZ);
when(mMockWiFiManager.getConnectionInfo()).thenReturn(mockWifiInfo);

assertEquals(true, mWiseFy.isNetwork5gHz(mockWifiInfo));
Expand Down Expand Up @@ -939,6 +1118,11 @@ public void isNetworkSecure_failure_nullCapabilities() {
assertEquals(false, mWiseFy.isNetworkSecure(scanResult));
}

@Test
public void isNetworkSecure_failure_nullScanResult() {
assertEquals(false, mWiseFy.isNetworkSecure(null));
}

@Test
public void isWifiEnabled_failure() {
setManagers();
Expand All @@ -954,7 +1138,7 @@ public void isWifiEnabled_success() {
}

@Test
public void isWifiEnabled_failure_NullWifiManager() {
public void isWifiEnabled_failure_nullWifiManager() {
setManagersToNull();
assertEquals(false, mWiseFy.isWifiEnabled());
}
Expand Down Expand Up @@ -1046,4 +1230,8 @@ private void setManagersToNull() {
mWiseFy.mWifiManager = null;
mWiseFy.mConnectivityManager = null;
}

private void setConnectivityManagerToNull() {
mWiseFy.mConnectivityManager = null;
}
}
Loading

0 comments on commit db218ba

Please sign in to comment.