Skip to content

Commit

Permalink
adapt test to migrated code
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Oct 31, 2023
1 parent d5dc025 commit 753bd0b
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class ConnectivityServiceTest {
fun `wifi is disconnected`() {
whenever(networkInfo.isConnectedOrConnecting).thenReturn(false)
whenever(networkInfo.type).thenReturn(ConnectivityManager.TYPE_WIFI)
connectivityService.connectivity.apply {
connectivityService.getConnectivity().apply {
assertFalse(isConnected)
assertTrue(isWifi)
}
Expand All @@ -153,7 +153,7 @@ class ConnectivityServiceTest {
@Test
fun `no active network`() {
whenever(platformConnectivityManager.activeNetworkInfo).thenReturn(null)
assertSame(Connectivity.DISCONNECTED, connectivityService.connectivity)
assertSame(Connectivity.DISCONNECTED, connectivityService.getConnectivity())
}
}

Expand All @@ -163,8 +163,8 @@ class ConnectivityServiceTest {
fun `connected to wifi`() {
whenever(networkInfo.isConnectedOrConnecting).thenReturn(true)
whenever(networkInfo.type).thenReturn(ConnectivityManager.TYPE_WIFI)
assertTrue(connectivityService.connectivity.isConnected)
assertTrue(connectivityService.connectivity.isWifi)
assertTrue(connectivityService.getConnectivity().isConnected)
assertTrue(connectivityService.getConnectivity().isWifi)
}

@Test
Expand All @@ -184,7 +184,7 @@ class ConnectivityServiceTest {
)
)
whenever(platformConnectivityManager.allNetworkInfo).thenReturn(wifiNetworkInfoList)
connectivityService.connectivity.let {
connectivityService.getConnectivity().let {
assertTrue(it.isConnected)
assertTrue(it.isWifi)
}
Expand All @@ -195,7 +195,7 @@ class ConnectivityServiceTest {
whenever(networkInfo.isConnectedOrConnecting).thenReturn(true)
whenever(networkInfo.type).thenReturn(ConnectivityManager.TYPE_MOBILE)
whenever(platformConnectivityManager.allNetworkInfo).thenReturn(arrayOf(networkInfo))
connectivityService.connectivity.let {
connectivityService.getConnectivity().let {
assertTrue(it.isConnected)
assertFalse(it.isWifi)
}
Expand All @@ -211,7 +211,7 @@ class ConnectivityServiceTest {
whenever(user.server).thenReturn(legacyServer)
assertTrue(
"Precondition failed",
connectivityService.connectivity.let {
connectivityService.getConnectivity().let {
it.isConnected && it.isWifi
}
)
Expand All @@ -228,19 +228,19 @@ class ConnectivityServiceTest {
@Test
fun `true maintenance status flag is used`() {
mockResponse(maintenance = true, httpStatus = HttpStatus.SC_OK)
assertTrue(connectivityService.isInternetWalled)
assertTrue(connectivityService.isInternetWalled())
}

@Test
fun `maintenance flag is ignored when non-200 HTTP code is returned`() {
mockResponse(maintenance = false, httpStatus = HttpStatus.SC_NO_CONTENT)
assertTrue(connectivityService.isInternetWalled)
assertTrue(connectivityService.isInternetWalled())
}

@Test
fun `status endpoint is used to determine internet state`() {
mockResponse()
connectivityService.isInternetWalled
connectivityService.isInternetWalled()
val urlCaptor = ArgumentCaptor.forClass(String::class.java)
verify(requestBuilder).invoke(urlCaptor.capture())
assertTrue("Invalid URL used to check status", urlCaptor.value.endsWith("/204"))
Expand All @@ -254,7 +254,7 @@ class ConnectivityServiceTest {
whenever(networkInfo.isConnectedOrConnecting).thenReturn(true)
whenever(networkInfo.type).thenReturn(ConnectivityManager.TYPE_WIFI)
whenever(accountManager.getServerVersion(any())).thenReturn(OwnCloudVersion.nextcloud_20)
connectivityService.connectivity.let {
connectivityService.getConnectivity().let {
assertTrue(it.isConnected)
assertTrue(it.isWifi)
assertFalse(it.isMetered)
Expand All @@ -270,7 +270,7 @@ class ConnectivityServiceTest {

// WHEN
// connectivity is checked
val result = connectivityService.isInternetWalled
val result = connectivityService.isInternetWalled()

// THEN
// connection is walled
Expand All @@ -287,15 +287,15 @@ class ConnectivityServiceTest {
// wifi is metered
whenever(networkCapabilities.hasCapability(any())).thenReturn(false) // this test is mocked for API M
whenever(platformConnectivityManager.isActiveNetworkMetered).thenReturn(true)
connectivityService.connectivity.let {
connectivityService.getConnectivity().let {
assertTrue("should be connected", it.isConnected)
assertTrue("should be connected to wifi", it.isWifi)
assertTrue("check mocking, this check is complicated and depends on SDK version", it.isMetered)
}

// WHEN
// connectivity is checked
val result = connectivityService.isInternetWalled
val result = connectivityService.isInternetWalled()

// THEN
// assume internet is not walled
Expand All @@ -315,7 +315,7 @@ class ConnectivityServiceTest {

// WHEN
// connectivity is checked
val result = connectivityService.isInternetWalled
val result = connectivityService.isInternetWalled()

// THEN
// connection is walled
Expand All @@ -335,14 +335,14 @@ class ConnectivityServiceTest {
@Test
fun `status 204 means internet is not walled`() {
mockResponse(contentLength = 0, status = HttpStatus.SC_NO_CONTENT)
assertFalse(connectivityService.isInternetWalled)
assertFalse(connectivityService.isInternetWalled())
verify(getRequest, times(1)).execute(client)
}

@Test
fun `status 204 and no content length means internet is not walled`() {
mockResponse(contentLength = -1, status = HttpStatus.SC_NO_CONTENT)
assertFalse(connectivityService.isInternetWalled)
assertFalse(connectivityService.isInternetWalled())
verify(getRequest, times(1)).execute(client)
}

Expand All @@ -356,7 +356,7 @@ class ConnectivityServiceTest {
@Test
fun `index endpoint is used to determine internet state`() {
mockResponse()
connectivityService.isInternetWalled
connectivityService.isInternetWalled()
val urlCaptor = ArgumentCaptor.forClass(String::class.java)
verify(requestBuilder).invoke(urlCaptor.capture())
assertTrue("Invalid URL used to check status", urlCaptor.value.endsWith("/index.php/204"))
Expand Down

0 comments on commit 753bd0b

Please sign in to comment.