1 /* 2 * Copyright (C) 2017 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.vpn2; 18 19 import static org.mockito.Mockito.never; 20 import static org.mockito.Mockito.verify; 21 22 import android.content.pm.PackageInfo; 23 24 import androidx.fragment.app.Fragment; 25 26 import org.junit.Before; 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 import org.mockito.Mock; 30 import org.mockito.MockitoAnnotations; 31 import org.robolectric.RobolectricTestRunner; 32 33 @RunWith(RobolectricTestRunner.class) 34 public class AppDialogFragmentTest { 35 36 @Mock 37 private Fragment mParent; 38 39 private PackageInfo mPackageInfo; 40 41 @Before setUp()42 public void setUp() { 43 MockitoAnnotations.initMocks(this); 44 mPackageInfo = new PackageInfo(); 45 } 46 47 @Test notManagingOrConnected_shouldNotShow()48 public void notManagingOrConnected_shouldNotShow() { 49 AppDialogFragment 50 .show(mParent, mPackageInfo, "label", false /* manage */, false /* connected */); 51 52 verify(mParent, never()).isAdded(); 53 } 54 55 @Test notManagingAndConnected_showShow()56 public void notManagingAndConnected_showShow() { 57 AppDialogFragment 58 .show(mParent, mPackageInfo, "label", false /* manage */, true /* connected */); 59 60 verify(mParent).isAdded(); 61 } 62 } 63