1 /* 2 * Copyright (C) 2025 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 package com.android.dependencymapper; 17 18 import org.junit.Test; 19 20 import static org.junit.Assert.assertEquals; 21 22 import com.android.dependencymapper.Utils; 23 24 public class UtilsTest { 25 26 @Test testTrimAndConvertToPackageBasedPath()27 public void testTrimAndConvertToPackageBasedPath() { 28 String testPath1 = "com/android/storage/StorageManager.class"; 29 String testPath2 = "com/android/package/PackageManager$Package.class"; 30 31 String expectedPackageBasedPath1 = "com.android.storage.StorageManager"; 32 String expectedPackageBasedPath2 = "com.android.package.PackageManager$Package"; 33 34 assertEquals("Package Based Path not constructed correctly", 35 expectedPackageBasedPath1, Utils.trimAndConvertToPackageBasedPath(testPath1)); 36 assertEquals("Package Based Path not constructed correctly", 37 expectedPackageBasedPath2, Utils.trimAndConvertToPackageBasedPath(testPath2)); 38 } 39 40 @Test testBuildPackagePrependedClassSource()41 public void testBuildPackagePrependedClassSource() { 42 String qualifiedClassPath1 = "com.android.storage.StorageManager"; 43 String sourcePath1 = "StorageManager.java"; 44 String qualifiedClassPath2 = "com.android.package.PackageManager$Package"; 45 String sourcePath2 = "PackageManager.java"; 46 String qualifiedClassPath3 = "com.android.storage.StorageManager$Storage"; 47 String sourcePath3 = "StorageManager$Storage.java"; 48 49 50 String expectedPackagePrependedPath1 = "com.android.storage.StorageManager.java"; 51 String expectedPackagePrependedPath2 = "com.android.package.PackageManager.java"; 52 String expectedPackagePrependedPath3 = "com.android.storage.StorageManager$Storage.java"; 53 54 assertEquals("Package Prepended Class Source not constructed correctly", 55 expectedPackagePrependedPath1, 56 Utils.buildPackagePrependedClassSource(qualifiedClassPath1, sourcePath1)); 57 assertEquals("Package Prepended Class Source not constructed correctly", 58 expectedPackagePrependedPath2, 59 Utils.buildPackagePrependedClassSource(qualifiedClassPath2, sourcePath2)); 60 assertEquals("Package Prepended Class Source not constructed correctly", 61 expectedPackagePrependedPath3, 62 Utils.buildPackagePrependedClassSource(qualifiedClassPath3, sourcePath3)); 63 } 64 } 65