1 /* 2 * Copyright (C) 2008 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 android.content.pm.cts; 18 19 import android.content.pm.ApplicationInfo; 20 import android.content.pm.PackageManager; 21 import android.content.pm.ApplicationInfo.DisplayNameComparator; 22 import android.content.pm.PackageManager.NameNotFoundException; 23 import android.test.AndroidTestCase; 24 25 /** 26 * Test {@link DisplayNameComparator}. 27 */ 28 public class ApplicationInfo_DisplayNameComparatorTest extends AndroidTestCase { 29 private static final String PACKAGE_NAME = "android.content.cts"; 30 DisplayNameComparator mDisplayNameComparator; 31 32 @Override 33 protected void setUp() throws Exception { 34 super.setUp(); 35 mDisplayNameComparator = null; 36 } 37 38 public void testConstructor() { 39 PackageManager pm = getContext().getPackageManager(); 40 new DisplayNameComparator(pm); 41 42 new DisplayNameComparator(null); 43 } 44 45 public void testCompare() throws NameNotFoundException { 46 PackageManager pm = getContext().getPackageManager(); 47 mDisplayNameComparator = new ApplicationInfo.DisplayNameComparator(pm); 48 49 ApplicationInfo info1 = new ApplicationInfo(); 50 ApplicationInfo info2 = new ApplicationInfo(); 51 info1.packageName = PACKAGE_NAME; 52 info2.packageName = PACKAGE_NAME; 53 assertEquals(0, mDisplayNameComparator.compare(info1, info2)); 54 55 info1 = mContext.getPackageManager().getApplicationInfo(PACKAGE_NAME, 0); 56 info2.packageName = PACKAGE_NAME + ".2"; 57 assertTrue((mDisplayNameComparator.compare(info1, info2) < 0)); 58 59 info1 = new ApplicationInfo(); 60 info1.packageName = PACKAGE_NAME + ".1"; 61 info2 = mContext.getPackageManager().getApplicationInfo(PACKAGE_NAME, 0); 62 assertTrue((mDisplayNameComparator.compare(info1, info2) > 0)); 63 64 try { 65 mDisplayNameComparator.compare(null, null); 66 fail("should throw NullPointerException."); 67 } catch (NullPointerException e) { 68 // expected 69 } 70 } 71 } 72