FragmentContentIdTest.java revision d88c4e9369baf40350063466d42f8f242f8641e0
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 android.support.v7.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.filters.Suppress;
27import android.support.v7.appcompat.test.R;
28
29import org.junit.Test;
30
31public class FragmentContentIdTest extends BaseInstrumentationTestCase<FragmentContentIdActivity> {
32
33    public FragmentContentIdTest() {
34        super(FragmentContentIdActivity.class);
35    }
36
37    @Suppress
38    @SmallTest
39    @Test
40    public void testFragmentAddedToAndroidContentIdCanBeRemoved() throws Throwable {
41        mActivityTestRule.runOnUiThread(new Runnable() {
42            @Override
43            public void run() {
44                mActivityTestRule.getActivity().replaceWithFragmentB();
45            }
46        });
47
48        // Ensure that fragment_a has been removed from the view hierarchy
49        onView(withId(R.id.fragment_a)).check(doesNotExist());
50        // And that fragment_b is displayed
51        onView(withId(R.id.fragment_b)).check(matches(isDisplayed()));
52    }
53
54}
55