Skip to content

Commit

Permalink
Start of 2.x
Browse files Browse the repository at this point in the history
close #58
close #59
close #60
close #61
close #62
close #64
  • Loading branch information
isuPatches committed Jul 9, 2017
1 parent 9cb52a6 commit 0a3cc80
Show file tree
Hide file tree
Showing 54 changed files with 5,591 additions and 1,440 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1'
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"
classpath "org.jacoco:org.jacoco.agent:0.7.8"
classpath "org.jacoco:org.jacoco.report:0.7.8"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3"
classpath "org.jacoco:org.jacoco.core:0.7.9"
classpath "org.jacoco:org.jacoco.agent:0.7.9"
classpath "org.jacoco:org.jacoco.report:0.7.9"
}
}

Expand Down Expand Up @@ -46,7 +46,7 @@ subprojects {

ext {
GROUP = "com.isupatches"
VERSION_NAME = "1.0.10"
VERSION_NAME = "2.0.0-BETA"

BINTRAY_REPO = "Maven"
BINTRAY_NAME = "wisefy"
Expand Down
10 changes: 6 additions & 4 deletions wisefy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ android {
unitTests.returnDefaultValues = true;
}

compileSdkVersion 25
compileSdkVersion 26
buildToolsVersion "25.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 9
targetSdkVersion 26
versionCode 10
versionName version
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
Expand All @@ -55,14 +55,16 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.android.support:support-annotations:25.3.1'

androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'org.mockito:mockito-android:2.8.47'
androidTestCompile 'com.android.support.test:runner:0.5'
// For issue #55 / IllegalAccessError conflict test
androidTestCompile 'com.google.android.gms:play-services-gcm:8.3.0'

testCompile 'org.mockito:mockito-core:2.7.19'
testCompile 'org.mockito:mockito-core:2.8.47'
testCompile 'junit:junit:4.12'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package com.isupatches.wisefy.test;


import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import com.isupatches.wisefy.WiseFy;
import com.isupatches.wisefy.callbacks.AddOpenNetworkCallbacks;
import com.isupatches.wisefy.constants.WiseFyCodes;
import com.isupatches.wisefy.test.base.BaseTestClass;
import com.isupatches.wisefy.test.base.TestActivity;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static com.isupatches.wisefy.test.base.TestUtils.OPEN_NETWORK_SSID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
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<TestActivity> {

public AddOpenNetworkTests() {
super(TestActivity.class);
}

@Test
public void noCallbacks_failure() {
setManagers();
when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE);
int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID);
assertEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
}

@Test
public void noCallbacks_failure_nullSSID() {
int result = mWiseFy.addOpenNetwork(null);
assertEquals(WiseFyCodes.MISSING_PARAMETER, result);
}

@Test
public void noCallbacks_failure_nullWifiManager() {
setManagersToNull();
int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID);
assertEquals(WiseFyCodes.NULL_MANAGER, result);
}

@Test
public void noCallbacks_success() {
setManagers();
when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0);
int result = mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID);
assertNotEquals(WiseFy.WIFI_MANAGER_FAILURE, result);
}

@Test
public void noCallbacks_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);
assertEquals(WiseFyCodes.NETWORK_ALREADY_CONFIGURED, result);
}

@Test
public void callbacks_failure() {
setManagers();
when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE);
AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockAddNetworkCallbacks);
verify(mockAddNetworkCallbacks, timeout(3000)).failureAddingOpenNetwork(WiseFy.WIFI_MANAGER_FAILURE);
}

@Test
public void callbacks_failure_nullCallback() {
setManagers();
when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(WiseFy.WIFI_MANAGER_FAILURE);
AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null);
verify(mockAddNetworkCallbacks, never()).failureAddingOpenNetwork(WiseFy.WIFI_MANAGER_FAILURE);
}

@Test
public void callbacks_failure_nullSSID() {
setManagers();
AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(null, mockAddNetworkCallbacks);
verify(mockAddNetworkCallbacks, timeout(3000)).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER);
}

@Test
public void callbacks_failure_nullSSID_nullCallback() {
setManagers();
AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(null, null);
verify(mockAddNetworkCallbacks, never()).addOpenNetworkWiseFyFailure(WiseFyCodes.MISSING_PARAMETER);
}

@Test
public void callbacks_failure_nullWifiManager() {
setManagersToNull();
AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockAddNetworkCallbacks);
verify(mockAddNetworkCallbacks, timeout(3000)).addOpenNetworkWiseFyFailure(WiseFyCodes.NULL_MANAGER);
}

@Test
public void callbacks_failure_nullWifiManager_nullCallback() {
setManagersToNull();
AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null);
verify(mockAddNetworkCallbacks, never()).addOpenNetworkWiseFyFailure(WiseFyCodes.NULL_MANAGER);
}

@Test
public void callbacks_success() {
setManagers();
when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0);
AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockAddNetworkCallbacks);
verify(mockAddNetworkCallbacks, timeout(3000)).openNetworkAdded(any(WifiConfiguration.class));
}

@Test
public void callbacks_success_nullCallback() {
setManagers();
when(mMockWiFiManager.addNetwork(any(WifiConfiguration.class))).thenReturn(0);
AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null);
verify(mockAddNetworkCallbacks, never()).openNetworkAdded(any(WifiConfiguration.class));
}

@Test
public void callbacks_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);

AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockAddNetworkCallbacks);
verify(mockAddNetworkCallbacks, timeout(3000)).addOpenNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED);
}

@Test
public void callbacks_success_alreadyConfigured_nullCallback() {
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);

AddOpenNetworkCallbacks mockAddNetworkCallbacks = mock(AddOpenNetworkCallbacks.class);
mWiseFy.addOpenNetwork(OPEN_NETWORK_SSID, null);
verify(mockAddNetworkCallbacks, never()).addOpenNetworkWiseFyFailure(WiseFyCodes.NETWORK_ALREADY_CONFIGURED);
}
}
Loading

0 comments on commit 0a3cc80

Please sign in to comment.