Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
isuPatches committed Aug 19, 2018
1 parent 4ac45e5 commit 845b8cb
Show file tree
Hide file tree
Showing 35 changed files with 212 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.mockito.Mockito.mock
*/
internal open class BaseAndroidJUnit4TestClass {

protected val wiseFy: WiseFy
protected val wisefy: WiseFy
protected val mockWiseFySearch: WiseFySearch

protected val mockConnectivityManager: ConnectivityManager
Expand All @@ -41,7 +41,7 @@ internal open class BaseAndroidJUnit4TestClass {
mockWifiManager = mock(WifiManager::class.java)
mockConnectivityManager = mock(ConnectivityManager::class.java)

wiseFy = WiseFy.Brains(InstrumentationRegistry.getTargetContext())
wisefy = WiseFy.Brains(InstrumentationRegistry.getTargetContext())
.customConnectivityManager(mockConnectivityManager)
.customWifiManager(mockWifiManager)
.customWiseFyConnection(mockWiseFyConnection)
Expand All @@ -56,13 +56,13 @@ internal open class BaseAndroidJUnit4TestClass {
mockWiseFyPrechecksUtil = MockWiseFyPrechecksUtil(mockWiseFyPrechecks)
mockWiseFySearchUtil = MockWiseFySearchUtil(mockWiseFySearch)

nullCallbackUtil = NullCallbackUtil(wiseFy)
nullCallbackUtil = NullCallbackUtil(wisefy)

verificationUtil = VerificationUtil(mockConnectivityManager, mockWifiManager)
}

@After fun tearDown() {
wiseFy.dump()
wisefy.dump()
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ internal class AddOpenNetworkTests : BaseAndroidJUnit4TestClass() {

@Test fun sync_failure_prechecks() {
mockWiseFyPrechecksUtil.addNetwork_failure()
assertEquals(MISSING_PARAMETER, wiseFy.addOpenNetwork(OPEN_NETWORK_SSID))
assertEquals(MISSING_PARAMETER, wisefy.addOpenNetwork(OPEN_NETWORK_SSID))
verificationUtil.didNoTryToAddNetwork()
}

@Test fun sync_failure() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_failure()
assertEquals(WIFI_MANAGER_FAILURE, wiseFy.addOpenNetwork(OPEN_NETWORK_SSID))
assertEquals(WIFI_MANAGER_FAILURE, wisefy.addOpenNetwork(OPEN_NETWORK_SSID))
verificationUtil.triedToAddNetwork()
}

@Test fun sync_success() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_success()
assertNotEquals(WIFI_MANAGER_FAILURE, wiseFy.addOpenNetwork(OPEN_NETWORK_SSID))
assertNotEquals(WIFI_MANAGER_FAILURE, wisefy.addOpenNetwork(OPEN_NETWORK_SSID))
verificationUtil.triedToAddNetwork()
}

@Test fun async_failure_prechecks() {
mockWiseFyPrechecksUtil.addNetwork_failure()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks)
wisefy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER)
verificationUtil.didNoTryToAddNetwork()
}
Expand All @@ -60,7 +60,7 @@ internal class AddOpenNetworkTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_failure()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks)
wisefy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).failureAddingNetwork(WIFI_MANAGER_FAILURE)
verificationUtil.triedToAddNetwork()
}
Expand All @@ -76,7 +76,7 @@ internal class AddOpenNetworkTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_success()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks)
wisefy.addOpenNetwork(OPEN_NETWORK_SSID, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).networkAdded(anyInt(), any(WifiConfiguration::class.java))
verificationUtil.triedToAddNetwork()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ internal class AddWEPNetworkTests : BaseAndroidJUnit4TestClass() {

@Test fun sync_failure_prechecks() {
mockWiseFyPrechecksUtil.addNetwork_failure()
assertEquals(MISSING_PARAMETER, wiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD))
assertEquals(MISSING_PARAMETER, wisefy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD))
verificationUtil.didNoTryToAddNetwork()
}

@Test fun sync_failure() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_failure()
assertEquals(WIFI_MANAGER_FAILURE, wiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD))
assertEquals(WIFI_MANAGER_FAILURE, wisefy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD))
verificationUtil.triedToAddNetwork()
}

@Test fun sync_success() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_success()
assertNotEquals(1, wiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD))
assertNotEquals(1, wisefy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD))
verificationUtil.triedToAddNetwork()
}

@Test fun async_failure_prechecks() {
mockWiseFyPrechecksUtil.addNetwork_failure()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks)
wisefy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER)
verificationUtil.didNoTryToAddNetwork()
}
Expand All @@ -61,7 +61,7 @@ internal class AddWEPNetworkTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_failure()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks)
wisefy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).failureAddingNetwork(WIFI_MANAGER_FAILURE)
verificationUtil.triedToAddNetwork()
}
Expand All @@ -77,7 +77,7 @@ internal class AddWEPNetworkTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_success()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks)
wisefy.addWEPNetwork(WEP_NETWORK_SSID, WEP_NETWORK_PASSWORD, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).networkAdded(anyInt(), any(WifiConfiguration::class.java))
verificationUtil.triedToAddNetwork()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ internal class AddWPA2NetworkTests : BaseAndroidJUnit4TestClass() {

@Test fun sync_failure_prechecks() {
mockWiseFyPrechecksUtil.addNetwork_failure()
assertEquals(MISSING_PARAMETER, wiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD))
assertEquals(MISSING_PARAMETER, wisefy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD))
verificationUtil.didNoTryToAddNetwork()
}

@Test fun sync_failure() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_failure()
assertEquals(WIFI_MANAGER_FAILURE, wiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD))
assertEquals(WIFI_MANAGER_FAILURE, wisefy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD))
verificationUtil.triedToAddNetwork()
}

@Test fun sync_success() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_success()
assertNotEquals(WIFI_MANAGER_FAILURE, wiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD))
assertNotEquals(WIFI_MANAGER_FAILURE, wisefy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD))
verificationUtil.triedToAddNetwork()
}

@Test fun async_failure_prechecks() {
mockWiseFyPrechecksUtil.addNetwork_failure()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks)
wisefy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER)
verificationUtil.didNoTryToAddNetwork()
}
Expand All @@ -61,7 +61,7 @@ internal class AddWPA2NetworkTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_failure()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks)
wisefy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).failureAddingNetwork(WIFI_MANAGER_FAILURE)
verificationUtil.triedToAddNetwork()
}
Expand All @@ -77,7 +77,7 @@ internal class AddWPA2NetworkTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.addNetwork_success()
mockNetworkUtil.addNetwork_success()
val mockCallbacks = mock(AddNetworkCallbacks::class.java)
wiseFy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks)
wisefy.addWPA2Network(WPA2_NETWORK_SSID, WPA2_NETWORK_PASSWORD, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).networkAdded(anyInt(), any(WifiConfiguration::class.java))
verificationUtil.triedToAddNetwork()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,37 @@ internal class ConnectToNetworkTests : BaseAndroidJUnit4TestClass() {

@Test fun sync_failure_prechecks() {
mockWiseFyPrechecksUtil.connectToNetwork_failure()
assertEquals(false, wiseFy.connectToNetwork(TEST_SSID, TEST_TIMEOUT))
assertEquals(false, wisefy.connectToNetwork(TEST_SSID, TEST_TIMEOUT))
verificationUtil.didNotTryToConnectToNetwork()
}

@Test fun sync_failure_noSavedNetwork() {
mockWiseFyPrechecksUtil.connectToNetwork_success()
mockWiseFySearchUtil.findSavedNetworkByRegex_null()
assertEquals(false, wiseFy.connectToNetwork(TEST_SSID, TEST_TIMEOUT))
assertEquals(false, wisefy.connectToNetwork(TEST_SSID, TEST_TIMEOUT))
verificationUtil.didNotTryToConnectToNetwork()
}

@Test fun sync_failure() {
mockWiseFyPrechecksUtil.connectToNetwork_success()
mockWiseFySearchUtil.findSavedNetworkByRegex_success()
mockWiseFyConnectionUtil.waitToConnectToSSID(false)
assertEquals(false, wiseFy.connectToNetwork(TEST_SSID, TEST_TIMEOUT))
assertEquals(false, wisefy.connectToNetwork(TEST_SSID, TEST_TIMEOUT))
verificationUtil.triedToConnectToNetwork()
}

@Test fun sync_success() {
mockWiseFyPrechecksUtil.connectToNetwork_success()
mockWiseFySearchUtil.findSavedNetworkByRegex_success()
mockWiseFyConnectionUtil.waitToConnectToSSID(true)
assertEquals(true, wiseFy.connectToNetwork(TEST_SSID, TEST_TIMEOUT))
assertEquals(true, wisefy.connectToNetwork(TEST_SSID, TEST_TIMEOUT))
verificationUtil.triedToConnectToNetwork()
}

@Test fun async_failure_prechecks() {
mockWiseFyPrechecksUtil.connectToNetwork_failure()
val mockCallbacks = mock(ConnectToNetworkCallbacks::class.java)
wiseFy.connectToNetwork(TEST_SSID, TEST_TIMEOUT, mockCallbacks)
wisefy.connectToNetwork(TEST_SSID, TEST_TIMEOUT, mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER)
verificationUtil.didNotTryToConnectToNetwork()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ internal class DisableWifiTests : BaseAndroidJUnit4TestClass() {

@Test fun sync_failure_prechecks() {
mockWiseFyPrechecksUtil.disableWifi_failure()
assertEquals(false, wiseFy.disableWifi())
assertEquals(false, wisefy.disableWifi())
verificationUtil.didNotTryToDisableWifi()
}

@Test fun sync_failure() {
mockWiseFyPrechecksUtil.disableWifi_success()
mockNetworkUtil.disableWifi_failure()
assertEquals(false, wiseFy.disableWifi())
assertEquals(false, wisefy.disableWifi())
verificationUtil.triedToDisableWifi()
}

@Test fun sync_success() {
mockWiseFyPrechecksUtil.disableWifi_success()
mockNetworkUtil.disableWifi_success()
assertEquals(true, wiseFy.disableWifi())
assertEquals(true, wisefy.disableWifi())
verificationUtil.triedToDisableWifi()
}

@Test fun async_failure_prechecks() {
mockWiseFyPrechecksUtil.disableWifi_failure()
val mockCallbacks = mock(DisableWifiCallbacks::class.java)
wiseFy.disableWifi(mockCallbacks)
wisefy.disableWifi(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER)
verificationUtil.didNotTryToDisableWifi()
}
Expand All @@ -57,7 +57,7 @@ internal class DisableWifiTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.disableWifi_success()
mockNetworkUtil.disableWifi_failure()
val mockCallbacks = mock(DisableWifiCallbacks::class.java)
wiseFy.disableWifi(mockCallbacks)
wisefy.disableWifi(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).failureDisablingWifi()
verificationUtil.triedToDisableWifi()
}
Expand All @@ -73,7 +73,7 @@ internal class DisableWifiTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.disableWifi_success()
mockNetworkUtil.disableWifi_success()
val mockCallbacks = mock(DisableWifiCallbacks::class.java)
wiseFy.disableWifi(mockCallbacks)
wisefy.disableWifi(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wifiDisabled()
verificationUtil.triedToDisableWifi()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ internal class DisconnectFromCurrentNetworkTests : BaseAndroidJUnit4TestClass()

@Test fun sync_failure_prechecks() {
mockWiseFyPrechecksUtil.disconnectFromCurrentNetwork_failure()
assertEquals(false, wiseFy.disconnectFromCurrentNetwork())
assertEquals(false, wisefy.disconnectFromCurrentNetwork())
verificationUtil.didNotTryToDisconnectFromCurrentNetwork()
}

@Test fun sync_failure() {
mockWiseFyPrechecksUtil.disconnectFromCurrentNetwork_success()
mockNetworkUtil.disconnectFromCurrentNetwork_failure()
assertEquals(false, wiseFy.disconnectFromCurrentNetwork())
assertEquals(false, wisefy.disconnectFromCurrentNetwork())
verificationUtil.triedToDisconnectFromCurrentNetwork()
}

@Test fun sync_success() {
mockWiseFyPrechecksUtil.disconnectFromCurrentNetwork_success()
mockNetworkUtil.disconnectFromCurrentNetwork_success()
assertEquals(true, wiseFy.disconnectFromCurrentNetwork())
assertEquals(true, wisefy.disconnectFromCurrentNetwork())
verificationUtil.triedToDisconnectFromCurrentNetwork()
}

@Test fun async_failure_prechecks() {
mockWiseFyPrechecksUtil.disconnectFromCurrentNetwork_failure()
val mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks::class.java)
wiseFy.disconnectFromCurrentNetwork(mockCallbacks)
wisefy.disconnectFromCurrentNetwork(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER)
verificationUtil.didNotTryToDisconnectFromCurrentNetwork()
}
Expand All @@ -57,7 +57,7 @@ internal class DisconnectFromCurrentNetworkTests : BaseAndroidJUnit4TestClass()
mockWiseFyPrechecksUtil.disconnectFromCurrentNetwork_success()
mockNetworkUtil.disconnectFromCurrentNetwork_failure()
val mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks::class.java)
wiseFy.disconnectFromCurrentNetwork(mockCallbacks)
wisefy.disconnectFromCurrentNetwork(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).failureDisconnectingFromCurrentNetwork()
verificationUtil.triedToDisconnectFromCurrentNetwork()
}
Expand All @@ -73,7 +73,7 @@ internal class DisconnectFromCurrentNetworkTests : BaseAndroidJUnit4TestClass()
mockWiseFyPrechecksUtil.disconnectFromCurrentNetwork_success()
mockNetworkUtil.disconnectFromCurrentNetwork_success()
val mockCallbacks = mock(DisconnectFromCurrentNetworkCallbacks::class.java)
wiseFy.disconnectFromCurrentNetwork(mockCallbacks)
wisefy.disconnectFromCurrentNetwork(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).disconnectedFromCurrentNetwork()
verificationUtil.triedToDisconnectFromCurrentNetwork()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ internal class EnableWifiTests : BaseAndroidJUnit4TestClass() {

@Test fun sync_failure_prechecks() {
mockWiseFyPrechecksUtil.enableWifi_failure()
assertEquals(false, wiseFy.enableWifi())
assertEquals(false, wisefy.enableWifi())
verificationUtil.didNotTryToEnableWifi()
}

@Test fun sync_failure() {
mockWiseFyPrechecksUtil.enableWifi_success()
mockNetworkUtil.enableWifi_failure()
assertEquals(false, wiseFy.enableWifi())
assertEquals(false, wisefy.enableWifi())
verificationUtil.triedToEnableWifi()
}

@Test fun sync_success() {
mockWiseFyPrechecksUtil.enableWifi_success()
mockNetworkUtil.enableWifi_success()
assertEquals(true, wiseFy.enableWifi())
assertEquals(true, wisefy.enableWifi())
verificationUtil.triedToEnableWifi()
}

@Test fun async_failure_prechecks() {
mockWiseFyPrechecksUtil.enableWifi_failure()
val mockCallbacks = mock(EnableWifiCallbacks::class.java)
wiseFy.enableWifi(mockCallbacks)
wisefy.enableWifi(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wisefyFailure(MISSING_PARAMETER)
verificationUtil.didNotTryToEnableWifi()
}
Expand All @@ -57,7 +57,7 @@ internal class EnableWifiTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.enableWifi_success()
mockNetworkUtil.enableWifi_failure()
val mockCallbacks = mock(EnableWifiCallbacks::class.java)
wiseFy.enableWifi(mockCallbacks)
wisefy.enableWifi(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).failureEnablingWifi()
verificationUtil.triedToEnableWifi()
}
Expand All @@ -73,7 +73,7 @@ internal class EnableWifiTests : BaseAndroidJUnit4TestClass() {
mockWiseFyPrechecksUtil.enableWifi_success()
mockNetworkUtil.enableWifi_success()
val mockCallbacks = mock(EnableWifiCallbacks::class.java)
wiseFy.enableWifi(mockCallbacks)
wisefy.enableWifi(mockCallbacks)
verify(mockCallbacks, timeout(VERIFICATION_SUCCESS_TIMEOUT)).wifiEnabled()
verificationUtil.triedToEnableWifi()
}
Expand Down
Loading

0 comments on commit 845b8cb

Please sign in to comment.