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 com.google.common.truth.Truth.assertThat; 20 21 import androidx.test.platform.app.InstrumentationRegistry; 22 import androidx.test.rule.ActivityTestRule; 23 24 import com.android.car.settings.R; 25 import com.android.car.settings.testutils.DualPaneTestActivity; 26 27 import org.junit.Rule; 28 import org.junit.Test; 29 30 import java.util.concurrent.atomic.AtomicReference; 31 32 public class DualPaneSettingsFragmentTest extends SettingsFragmentTestCase<DualPaneTestActivity> { 33 34 @Rule 35 public ActivityTestRule<DualPaneTestActivity> mActivityTestRule = 36 new ActivityTestRule<>(DualPaneTestActivity.class); 37 38 @Override getActivityTestRule()39 ActivityTestRule<DualPaneTestActivity> getActivityTestRule() { 40 return mActivityTestRule; 41 } 42 43 @Test launchFragment_otherFragment_opensFragment()44 public void launchFragment_otherFragment_opensFragment() throws Throwable { 45 AtomicReference<TestSettingsFragment> otherFragment = new AtomicReference<>(); 46 getActivityTestRule().runOnUiThread(() -> { 47 otherFragment.set(new TestSettingsFragment()); 48 mFragment.onCreate(null); 49 mFragment.launchFragment(otherFragment.get()); 50 }); 51 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); 52 assertThat( 53 mFragment.getFragmentManager().findFragmentById(R.id.fragment_container)).isEqualTo( 54 otherFragment.get()); 55 } 56 } 57