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.notification; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.mockito.Mockito.mock; 21 import static org.mockito.Mockito.spy; 22 23 import android.app.Application; 24 import android.app.PendingIntent; 25 import android.content.Intent; 26 import android.net.Uri; 27 import android.testing.AndroidTestingRunner; 28 import android.testing.TestableLooper.RunWithLooper; 29 30 import androidx.test.filters.SmallTest; 31 32 import com.android.server.UiServiceTestCase; 33 import com.android.server.pm.PackageManagerService; 34 35 import org.junit.Before; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.mockito.MockitoAnnotations; 39 40 @RunWith(AndroidTestingRunner.class) 41 @SmallTest 42 @RunWithLooper 43 public class EventConditionProviderTest extends UiServiceTestCase { 44 45 EventConditionProvider mService; 46 47 @Before setUp()48 public void setUp() throws Exception { 49 MockitoAnnotations.initMocks(this); 50 51 Intent startIntent = 52 new Intent("com.android.server.notification.EventConditionProvider"); 53 startIntent.setPackage("android"); 54 EventConditionProvider service = new EventConditionProvider(); 55 service.attach( 56 getContext(), 57 null, // ActivityThread not actually used in Service 58 CountdownConditionProvider.class.getName(), 59 null, // token not needed when not talking with the activity manager 60 mock(Application.class), 61 null // mocked services don't talk with the activity manager 62 ); 63 service.onCreate(); 64 service.onBind(startIntent); 65 mService = spy(service); 66 } 67 68 @Test testGetPendingIntent()69 public void testGetPendingIntent() { 70 PendingIntent pi = mService.getPendingIntent(1000); 71 assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME, pi.getIntent().getPackage()); 72 } 73 } 74