Skip to content

Commit

Permalink
Move all tests to AndroidJUnit4 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isuPatches committed Jul 24, 2017
1 parent 82a22ef commit 5c7f29e
Show file tree
Hide file tree
Showing 41 changed files with 5,240 additions and 5,457 deletions.
6 changes: 3 additions & 3 deletions gradle/jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TestActivity> {
//
// 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();
// }
// }
//}
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();
}
}
}
Loading

0 comments on commit 5c7f29e

Please sign in to comment.