Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d9a830a authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Add unit test coverage for BlockedNumbersUtil

Adding unit tests for updateEmergencyCallNotification method which
uses pending intents.  Ensures changes to that API contract do not cause
problems down the road.

Test: Add test coverage for uncovered methods.
Fixes: 191262422
Change-Id: Iaaa4581405c4b04a05dfdeadde60e4d9d9d1dd71
parent f4b84bad
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.telecom.tests;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.verify;

import android.app.Notification;
import android.app.NotificationManager;
import android.os.UserHandle;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.server.telecom.settings.BlockedNumbersUtil;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class BlockedNumbersUtilTests extends TelecomTestCase {
    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
    }

    @SmallTest
    @Test
    public void testPostNotification() {
        BlockedNumbersUtil.updateEmergencyCallNotification(mContext, true);
        NotificationManager mgr = mComponentContextFixture.getNotificationManager();
        verify(mgr).notifyAsUser(isNull(), anyInt(), any(Notification.class),
                any(UserHandle.class));
    }

    @SmallTest
    @Test
    public void testDismissNotification() {
        BlockedNumbersUtil.updateEmergencyCallNotification(mContext, false);
        NotificationManager mgr = mComponentContextFixture.getNotificationManager();
        verify(mgr).cancelAsUser(isNull(), anyInt(), any(UserHandle.class));
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -711,6 +711,10 @@ public class ComponentContextFixture implements TestFixture<Context> {
        return mTelephonyManager;
    }

    public NotificationManager getNotificationManager() {
        return mNotificationManager;
    }

    private void addService(String action, ComponentName name, IInterface service) {
        mComponentNamesByAction.put(action, name);
        mServiceByComponentName.put(name, service);