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 
39 @RunWith(RobolectricTestRunner.class)
40 public class NotificationAssistantDialogFragmentTest {
41 
42     private Context mContext;
43     @Mock
44     private ConfigureNotificationSettings mFragment;
45     private NotificationAssistantDialogFragment mDialogFragment;
46     @Mock
47     private FragmentActivity mActivity;
48 
49     ComponentName mComponentName = new ComponentName("a", "b");
50 
51     @Before
setUp()52     public void setUp() {
53         MockitoAnnotations.initMocks(this);
54         mContext = spy(RuntimeEnvironment.application);
55         mDialogFragment =
56                 spy(NotificationAssistantDialogFragment.newInstance(mFragment, mComponentName));
57         doReturn(mActivity).when(mDialogFragment).getActivity();
58         doReturn(mContext).when(mDialogFragment).getContext();
59 
60     }
61 
62 
63     @Test
testClickOK_callEnableNAS()64     public void testClickOK_callEnableNAS() {
65         mDialogFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
66 
67         verify(mFragment, times(1)).enableNAS(eq(mComponentName));
68     }
69 }
70