summaryrefslogtreecommitdiff
path: root/tests/src/com/android/providers/blockednumber/BlockedNumberContractTest.java
blob: 93e9cee4f5fb0e60390a2a393ab30a3727630126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (C) 2018 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.providers.blockednumber;

import static android.provider.BlockedNumberContract.STATUS_NOT_BLOCKED;
import static android.provider.BlockedNumberContract.SystemContract
        .ENHANCED_SETTING_KEY_BLOCK_PAYPHONE;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.provider.BlockedNumberContract;
import android.test.AndroidTestCase;
import android.test.mock.MockContentResolver;
import android.test.suitebuilder.annotation.SmallTest;

import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;

/**
 * Tests for {@link android.provider.BlockedNumberContract}.
 */
@RunWith(JUnit4.class)
public class BlockedNumberContractTest extends AndroidTestCase {
    private static final String TEST_NUMBER = "650-555-1212";

    @Mock
    private Context mMockContext;

    @Mock
    private ContentProvider mMockProvider;

    private MockContentResolver mMockContentResolver = new MockContentResolver();

    @Before
    @Override
    public void setUp() throws Exception {
        super.setUp();
        initMocks(this);
        mMockContentResolver.addProvider(BlockedNumberContract.AUTHORITY_URI.toString(),
                mMockProvider);
        when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver);
        when(mMockProvider.call(any(), any(), any()))
                .thenThrow(new NullPointerException());
    }

    /**
     * Ensures a content provider crash results in a "false" response from
     * {@link BlockedNumberContract#isBlocked(Context, String)}.
     */
    @SmallTest
    @Test
    public void testIsBlockedException() {
        assertFalse(BlockedNumberContract.isBlocked(mMockContext, TEST_NUMBER));
    }

    /**
     * Ensures a content provider crash results in a "false" response from
     * {@link BlockedNumberContract#canCurrentUserBlockNumbers(Context)}.
     */
    @SmallTest
    @Test
    public void testCanUserBlockNumbersException() {
        assertFalse(BlockedNumberContract.canCurrentUserBlockNumbers(mMockContext));
    }

    /**
     * Ensures a content provider crash results in a "false" response from
     * {@link BlockedNumberContract.SystemContract#shouldSystemBlockNumber(Context, String, Bundle)}
     */
    @SmallTest
    @Test
    public void testShouldSystemBlockNumberException() {
        assertEquals(STATUS_NOT_BLOCKED,
                BlockedNumberContract.SystemContract.shouldSystemBlockNumber(mMockContext,
                        TEST_NUMBER, null));
    }

    /**
     * Ensures a content provider crash results in a "false" response from
     * {@link BlockedNumberContract.SystemContract#shouldShowEmergencyCallNotification(Context)}.
     */
    @SmallTest
    @Test
    public void testShouldShowEmergencyCallNotificationException() {
        assertFalse(BlockedNumberContract.SystemContract.shouldShowEmergencyCallNotification(
                mMockContext));
    }

    /**
     * Ensures a content provider crash results in a "false" response from
     * {@link BlockedNumberContract.SystemContract#getEnhancedBlockSetting(Context, String)}.
     */
    @SmallTest
    @Test
    public void testGetEnhancedBlockSettingException() {
        assertFalse(BlockedNumberContract.SystemContract.getEnhancedBlockSetting(
                mMockContext, ENHANCED_SETTING_KEY_BLOCK_PAYPHONE));
    }
}