mirror of
https://github.com/ProtonMail/android-mail.git
synced 2026-06-14 09:54:47 +00:00
Move WebView mocking into a separate class in test utils
Minor changes needed to avoid duplication MAILANDR-1015
This commit is contained in:
committed by
MargeBot
parent
de84cea98c
commit
e69a5cee95
+4
-18
@@ -18,10 +18,8 @@
|
||||
|
||||
package ch.protonmail.android.mailcommon.data.system
|
||||
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageInfo
|
||||
import android.webkit.WebView
|
||||
import io.mockk.every
|
||||
import ch.protonmail.android.test.utils.mocks.WebViewProviderMocks.mockExpectedWebViewAvailableOnDevice
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkAll
|
||||
import org.junit.After
|
||||
@@ -44,7 +42,7 @@ class DeviceCapabilitiesImplTest {
|
||||
@Test
|
||||
fun `Should return web view not available when provider is not present`() {
|
||||
// Given
|
||||
expectedWebViewAvailableOnDevice(isPackagePresent = false)
|
||||
mockExpectedWebViewAvailableOnDevice(isPackagePresent = false)
|
||||
|
||||
// When
|
||||
val capabilities = DeviceCapabilitiesImpl().getCapabilities()
|
||||
@@ -56,7 +54,7 @@ class DeviceCapabilitiesImplTest {
|
||||
@Test
|
||||
fun `Should return web view not available when provider is present but not enabled`() {
|
||||
// Given
|
||||
expectedWebViewAvailableOnDevice(isPackagePresent = true, isPackageEnabled = false)
|
||||
mockExpectedWebViewAvailableOnDevice(isPackagePresent = true, isPackageEnabled = false)
|
||||
|
||||
// When
|
||||
val capabilities = DeviceCapabilitiesImpl().getCapabilities()
|
||||
@@ -68,7 +66,7 @@ class DeviceCapabilitiesImplTest {
|
||||
@Test
|
||||
fun `Should return web view available when provider is present and enabled`() {
|
||||
// Given
|
||||
expectedWebViewAvailableOnDevice(isPackagePresent = true, isPackageEnabled = true)
|
||||
mockExpectedWebViewAvailableOnDevice(isPackagePresent = true, isPackageEnabled = true)
|
||||
|
||||
// When
|
||||
val capabilities = DeviceCapabilitiesImpl().getCapabilities()
|
||||
@@ -76,16 +74,4 @@ class DeviceCapabilitiesImplTest {
|
||||
// Then
|
||||
assertEquals(true, capabilities.hasWebView)
|
||||
}
|
||||
|
||||
private fun expectedWebViewAvailableOnDevice(
|
||||
isPackagePresent: Boolean,
|
||||
isPackageEnabled: Boolean = false
|
||||
) {
|
||||
val packageInfo = PackageInfo().apply {
|
||||
applicationInfo = ApplicationInfo()
|
||||
applicationInfo.enabled = isPackageEnabled
|
||||
}
|
||||
|
||||
every { WebView.getCurrentWebViewPackage() } returns if (isPackagePresent) packageInfo else null
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Proton Technologies AG
|
||||
* This file is part of Proton Technologies AG and Proton Mail.
|
||||
*
|
||||
* Proton Mail is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Proton Mail is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Proton Mail. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ch.protonmail.android.test.utils.mocks
|
||||
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageInfo
|
||||
import android.webkit.WebView
|
||||
import io.mockk.every
|
||||
|
||||
object WebViewProviderMocks {
|
||||
|
||||
fun mockExpectedWebViewAvailableOnDevice(
|
||||
isPackagePresent: Boolean,
|
||||
isPackageEnabled: Boolean = false
|
||||
) {
|
||||
val packageInfo = PackageInfo().apply {
|
||||
applicationInfo = ApplicationInfo()
|
||||
applicationInfo.enabled = isPackageEnabled
|
||||
}
|
||||
|
||||
every { WebView.getCurrentWebViewPackage() } returns if (isPackagePresent) packageInfo else null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user