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.settings.notification;
18 
19 import static org.mockito.ArgumentMatchers.eq;
20 import static org.mockito.Mockito.doReturn;
21 import static org.mockito.Mockito.spy;
22 import static org.mockito.Mockito.times;
23 import static org.mockito.Mockito.verify;
24 
25 import android.content.ComponentName;
26 import android.content.Context;
27 import android.content.DialogInterface;
28 
29 import androidx.fragment.app.FragmentActivity;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.robolectric.RobolectricTestRunner;
37 import org.robolectric.RuntimeEnvironment;
38 import org.robolectric.annotation.Config;
39 
40 @RunWith(RobolectricTestRunner.class)
41 @Config(shadows = {
42         com.android.settings.testutils.shadow.ShadowFragment.class,
43 })
44 public class NotificationAssistantDialogFragmentTest {
45 
46     private Context mContext;
47     @Mock
48     private ConfigureNotificationSettings mFragment;
49     private NotificationAssistantDialogFragment mDialogFragment;
50     @Mock
51     private FragmentActivity mActivity;
52 
53     ComponentName mComponentName = new ComponentName("a", "b");
54 
55     @Before
setUp()56     public void setUp() {
57         MockitoAnnotations.initMocks(this);
58         mContext = spy(RuntimeEnvironment.application);
59         mDialogFragment =
60                 spy(NotificationAssistantDialogFragment.newInstance(mFragment, mComponentName));
61         doReturn(mActivity).when(mDialogFragment).getActivity();
62         doReturn(mContext).when(mDialogFragment).getContext();
63 
64     }
65 
66 
67     @Test
testClickOK_callEnableNAS()68     public void testClickOK_callEnableNAS() {
69         mDialogFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
70 
71         verify(mFragment, times(1)).enableNAS(eq(mComponentName));
72     }
73 }
74