1 /* 2 * Copyright (C) 2019 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.parsing.library; 18 19 import static org.junit.Assert.assertEquals; 20 21 import com.android.internal.pm.parsing.pkg.ParsedPackage; 22 import com.android.server.pm.pkg.AndroidPackage; 23 24 import java.util.function.Supplier; 25 26 /** 27 * Helper for classes that test {@link PackageSharedLibraryUpdater}. 28 */ 29 abstract class PackageSharedLibraryUpdaterTest { 30 31 protected static final String PACKAGE_NAME = "org.package.name"; 32 checkBackwardsCompatibility(ParsedPackage before, AndroidPackage after, boolean isSystemApp, Supplier<PackageSharedLibraryUpdater> updaterSupplier)33 static void checkBackwardsCompatibility(ParsedPackage before, AndroidPackage after, 34 boolean isSystemApp, Supplier<PackageSharedLibraryUpdater> updaterSupplier) { 35 updaterSupplier.get().updatePackage(before, isSystemApp, false); 36 check(before.hideAsFinal(), after); 37 } 38 check(AndroidPackage before, AndroidPackage after)39 private static void check(AndroidPackage before, AndroidPackage after) { 40 assertEquals("targetSdkVersion should not be changed", 41 after.getTargetSdkVersion(), 42 before.getTargetSdkVersion()); 43 assertEquals("usesLibraries not updated correctly", 44 after.getUsesLibraries(), 45 before.getUsesLibraries()); 46 assertEquals("usesOptionalLibraries not updated correctly", 47 after.getUsesOptionalLibraries(), 48 before.getUsesOptionalLibraries()); 49 } 50 } 51