1 /*
2  * Copyright (C) 2020 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.systemui.screenshot;
18 
19 import static com.android.systemui.screenshot.ScreenshotController.EXTRA_ACTION_TYPE;
20 import static com.android.systemui.screenshot.ScreenshotController.EXTRA_ID;
21 
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.ArgumentMatchers.eq;
24 import static org.mockito.ArgumentMatchers.isNull;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 
28 import android.app.PendingIntent;
29 import android.content.Intent;
30 import android.os.Bundle;
31 import android.testing.AndroidTestingRunner;
32 
33 import androidx.test.filters.SmallTest;
34 
35 import com.android.systemui.SysuiTestCase;
36 
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.mockito.Mock;
41 import org.mockito.MockitoAnnotations;
42 
43 @RunWith(AndroidTestingRunner.class)
44 @SmallTest
45 public class SmartActionsReceiverTest extends SysuiTestCase {
46 
47     @Mock
48     private ScreenshotSmartActions mMockScreenshotSmartActions;
49     @Mock
50     private PendingIntent mMockPendingIntent;
51 
52     private SmartActionsReceiver mSmartActionsReceiver;
53     private Intent mIntent;
54 
55     @Before
setup()56     public void setup() {
57         MockitoAnnotations.initMocks(this);
58         mSmartActionsReceiver = new SmartActionsReceiver(mMockScreenshotSmartActions);
59         mIntent = new Intent(mContext, SmartActionsReceiver.class)
60                 .putExtra(ScreenshotController.EXTRA_ACTION_INTENT, mMockPendingIntent);
61     }
62 
63     @Test
testSmartActionIntent()64     public void testSmartActionIntent() throws PendingIntent.CanceledException {
65         String testId = "testID";
66         String testActionType = "testActionType";
67         mIntent.putExtra(EXTRA_ID, testId);
68         mIntent.putExtra(EXTRA_ACTION_TYPE, testActionType);
69         Intent intent = new Intent();
70         when(mMockPendingIntent.getIntent()).thenReturn(intent);
71 
72         mSmartActionsReceiver.onReceive(mContext, mIntent);
73 
74         verify(mMockPendingIntent).send(
75                 eq(mContext), eq(0), isNull(), isNull(), isNull(), isNull(), any(Bundle.class));
76         verify(mMockScreenshotSmartActions).notifyScreenshotAction(
77                 testId, testActionType, true, intent);
78     }
79 }
80