1/*
2 * Copyright (C) 2016 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
17package androidx.appcompat.app;
18
19import static android.support.test.espresso.Espresso.onView;
20import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
21import static android.support.test.espresso.assertion.ViewAssertions.matches;
22import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
23import static android.support.test.espresso.matcher.ViewMatchers.withId;
24
25import android.support.test.filters.SmallTest;
26import android.support.test.rule.ActivityTestRule;
27import android.support.test.runner.AndroidJUnit4;
28
29import androidx.appcompat.test.R;
30
31import org.junit.Rule;
32import org.junit.Test;
33import org.junit.runner.RunWith;
34
35@RunWith(AndroidJUnit4.class)
36public class FragmentContentIdTest {
37    @Rule
38    public final ActivityTestRule<FragmentContentIdActivity> mActivityTestRule =
39            new ActivityTestRule<>(FragmentContentIdActivity.class);
40
41    @SmallTest
42    @Test
43    public void testFragmentAddedToAndroidContentIdCanBeRemoved() throws Throwable {
44        mActivityTestRule.runOnUiThread(new Runnable() {
45            @Override
46            public void run() {
47                mActivityTestRule.getActivity().replaceWithFragmentB();
48            }
49        });
50
51        // Ensure that fragment_a has been removed from the view hierarchy
52        onView(withId(R.id.fragment_a)).check(doesNotExist());
53        // And that fragment_b is displayed
54        onView(withId(R.id.fragment_b)).check(matches(isDisplayed()));
55    }
56}
57