Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cb2bb51 authored by Colin Cross's avatar Colin Cross
Browse files

Fix tests broken by @NonNull annotation fix

b/294110802 fixed the @NonNull annotation so that it was visible to
kotlin when applied to methods outside the current build module.  This
caused kotlin to insert more null checks, which broke some tests that
use mockito's when/thenReturn syntax, as that calls the method and
mockito may return null where kotlin doesn't expect it.  Fix them by
switching to the doReturn/when syntax, which doesn't call the method.

Bug: 294110802
Bug: 297916459
Bug: 297919489
Test: atest PackageManagerServiceTests FrameworksMockingServicesTests
Change-Id: I0ff1ce3200f73c5596e1f06ea653ff397b9024cb
parent 8792597c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import org.junit.Test
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mockito.doReturn
import kotlin.test.assertFailsWith

class PackageManagerLocalSnapshotTest {
@@ -154,7 +155,7 @@ class PackageManagerLocalSnapshotTest {
            put(packageStateUser0.packageName, packageStateUser0)
            put(packageStateUser10.packageName, packageStateUser10)
        }
        whenever(this.packageStates) { packageStates }
        doReturn(packageStates).whenever(this).packageStates
        whenever(getPackageStateFiltered(anyString(), anyInt(), anyInt())) {
            packageStates[arguments[0]]?.takeUnless {
                shouldFilterApplication(it, arguments[1] as Int, arguments[2] as Int)
+3 −2
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import org.mockito.Mockito.any
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.anyLong
import org.mockito.Mockito.anyString
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.eq
import org.mockito.Mockito.mock
import org.mockito.Mockito.verifyNoMoreInteractions
@@ -351,12 +352,12 @@ class DomainVerificationEnforcerTest {
                whenever(this.domainSetId) { domainSetId }
                whenever(getUserStateOrDefault(0)) { PackageUserStateInternal.DEFAULT }
                whenever(getUserStateOrDefault(1)) { PackageUserStateInternal.DEFAULT }
                whenever(userStates) {
                doReturn(
                    SparseArray<PackageUserStateInternal>().apply {
                        this[0] = PackageUserStateInternal.DEFAULT
                        this[1] = PackageUserStateInternal.DEFAULT
                    }
                }
                ).whenever(this).userStates
                whenever(isSystem) { false }
                whenever(signingDetails) { SigningDetails.UNKNOWN }
            }
+3 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyLong
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mockito.doReturn
import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.test.assertFailsWith
@@ -555,12 +556,12 @@ class DomainVerificationManagerApiTest {
        whenever(this.domainSetId) { domainSetId }
        whenever(getUserStateOrDefault(0)) { pkgUserState0() }
        whenever(getUserStateOrDefault(1)) { pkgUserState1() }
        whenever(userStates) {
        doReturn(
            SparseArray<PackageUserStateInternal>().apply {
                this[0] = pkgUserState0()
                this[1] = pkgUserState1()
            }
        }
        ).whenever(this).userStates
        whenever(isSystem) { false }
    }

+2 −2
Original line number Diff line number Diff line
@@ -1084,12 +1084,12 @@ class DomainVerificationPackageTest {
        whenever(this.domainSetId) { domainSetId }
        whenever(getUserStateOrDefault(0)) { PackageUserStateInternal.DEFAULT }
        whenever(getUserStateOrDefault(10)) { PackageUserStateInternal.DEFAULT }
        whenever(userStates) {
        doReturn(
            SparseArray<PackageUserStateInternal>().apply {
                this[0] = PackageUserStateInternal.DEFAULT
                this[1] = PackageUserStateInternal.DEFAULT
            }
        }
        ).whenever(this).userStates
        whenever(isSystem) { isSystemApp }

        val mockSigningDetails = SigningDetails(arrayOf(spy(Signature(signature)) {
+3 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import org.mockito.Mockito.any
import org.mockito.Mockito.anyInt
import org.mockito.Mockito.anyLong
import org.mockito.Mockito.anyString
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.eq
import org.mockito.Mockito.verify
import java.util.UUID
@@ -218,12 +219,12 @@ class DomainVerificationSettingsMutationTest {
            whenever(domainSetId) { TEST_UUID }
            whenever(getUserStateOrDefault(0)) { PackageUserStateInternal.DEFAULT }
            whenever(getUserStateOrDefault(10)) { PackageUserStateInternal.DEFAULT }
            whenever(userStates) {
            doReturn(
                SparseArray<PackageUserStateInternal>().apply {
                    this[0] = PackageUserStateInternal.DEFAULT
                    this[1] = PackageUserStateInternal.DEFAULT
                }
            }
            ).whenever(this).userStates
            whenever(isSystem) { false }
        }
    }
Loading