1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.pm.test.verify.domain 18 19 import com.android.internal.util.FunctionalUtils 20 import com.android.server.pm.PackageSetting 21 import com.android.server.pm.verify.domain.DomainVerificationManagerInternal 22 import com.android.server.testutils.whenever 23 import org.mockito.ArgumentMatchers.any 24 import java.util.function.Consumer 25 import java.util.function.Function 26 27 internal object DomainVerificationTestUtils { 28 29 @Suppress("UNCHECKED_CAST") mockPackageSettingsnull30 fun DomainVerificationManagerInternal.Connection.mockPackageSettings( 31 block: (String) -> PackageSetting? 32 ) { 33 whenever(withPackageSettingsSnapshot(any())) { 34 (arguments[0] as Consumer<Function<String, PackageSetting?>>).accept { block(it) } 35 } 36 whenever(withPackageSettingsSnapshotReturning<Any>(any())) { 37 (arguments[0] as FunctionalUtils.ThrowingFunction<Function<String, PackageSetting?>, *>) 38 .apply { block(it) } 39 } 40 whenever(withPackageSettingsSnapshotThrowing<Exception>(any())) { 41 (arguments[0] as FunctionalUtils.ThrowingCheckedConsumer< 42 Function<String, PackageSetting?>, *>) 43 .accept { block(it) } 44 } 45 whenever(withPackageSettingsSnapshotThrowing2<Exception, Exception>(any())) { 46 (arguments[0] as FunctionalUtils.ThrowingChecked2Consumer< 47 Function<String, PackageSetting?>, *, *>) 48 .accept { block(it) } 49 } 50 whenever(withPackageSettingsSnapshotReturningThrowing<Any, Exception>(any())) { 51 (arguments[0] as FunctionalUtils.ThrowingCheckedFunction< 52 Function<String, PackageSetting?>, *, *>) 53 .apply { block(it) } 54 } 55 } 56 } 57