• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.settings.common;
18 
19 import static org.mockito.ArgumentMatchers.any;
20 import static org.mockito.Mockito.never;
21 import static org.mockito.Mockito.spy;
22 import static org.mockito.Mockito.verify;
23 
24 import android.content.Intent;
25 
26 import androidx.preference.Preference;
27 import androidx.test.platform.app.InstrumentationRegistry;
28 import androidx.test.rule.ActivityTestRule;
29 
30 import com.android.car.settings.testutils.BaseCarSettingsTestActivity;
31 import com.android.car.settings.testutils.BaseTestSettingsFragment;
32 import com.android.car.settings.testutils.DualPaneTestActivity;
33 
34 import org.junit.Rule;
35 import org.junit.Test;
36 
37 public class DualPaneBaseCarSettingsActivityTest
38         extends BaseCarSettingsActivityTestCase<DualPaneTestActivity> {
39 
40     @Rule
41     public ActivityTestRule<DualPaneTestActivity> mActivityTestRule =
42             new ActivityTestRule<>(DualPaneTestActivity.class);
43 
44     @Override
getActivityTestRule()45     ActivityTestRule<DualPaneTestActivity> getActivityTestRule() {
46         return mActivityTestRule;
47     }
48 
49     @Test
onPreferenceStartFragment_startsActivity()50     public void onPreferenceStartFragment_startsActivity() throws Throwable {
51         Preference pref = new Preference(mContext);
52         pref.setFragment(BaseTestSettingsFragment.class.getName());
53 
54         BaseCarSettingsTestActivity spiedActivity = spy(mActivity);
55         verify(spiedActivity, never()).startActivity(any(Intent.class));
56 
57         mActivityTestRule.runOnUiThread(() ->
58                 spiedActivity.onPreferenceStartFragment(/* caller= */ null, pref));
59         InstrumentationRegistry.getInstrumentation().waitForIdleSync();
60 
61         verify(spiedActivity).startActivity(any(Intent.class));
62     }
63 }
64