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
17package android.support.v4.view;
18
19import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertTrue;
21
22import android.app.Activity;
23import android.graphics.Color;
24import android.graphics.drawable.ColorDrawable;
25import android.support.compat.test.R;
26import android.support.test.InstrumentationRegistry;
27import android.support.test.filters.MediumTest;
28import android.support.test.runner.AndroidJUnit4;
29import android.support.v4.BaseInstrumentationTestCase;
30import android.view.ViewGroup;
31
32import org.junit.Before;
33import org.junit.Test;
34import org.junit.runner.RunWith;
35
36
37@RunWith(AndroidJUnit4.class)
38@MediumTest
39public class ViewGroupCompatTest extends BaseInstrumentationTestCase<ViewCompatActivity> {
40
41    private ViewGroup mViewGroup;
42
43    public ViewGroupCompatTest() {
44        super(ViewCompatActivity.class);
45    }
46
47    @Before
48    public void setUp() {
49        final Activity activity = mActivityTestRule.getActivity();
50        mViewGroup = activity.findViewById(R.id.container);
51    }
52
53    @Test
54    public void isTransitionGroup() {
55        assertFalse(ViewGroupCompat.isTransitionGroup(mViewGroup));
56        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
57            @Override
58            public void run() {
59                ViewCompat.setBackground(mViewGroup, new ColorDrawable(Color.GRAY));
60            }
61        });
62        assertTrue(ViewGroupCompat.isTransitionGroup(mViewGroup));
63    }
64
65    @Test
66    public void setTransitionGroup() {
67        assertFalse(ViewGroupCompat.isTransitionGroup(mViewGroup));
68        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
69            @Override
70            public void run() {
71                ViewGroupCompat.setTransitionGroup(mViewGroup, true);
72            }
73        });
74        assertTrue(ViewGroupCompat.isTransitionGroup(mViewGroup));
75        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
76            @Override
77            public void run() {
78                ViewGroupCompat.setTransitionGroup(mViewGroup, false);
79            }
80        });
81        assertFalse(ViewGroupCompat.isTransitionGroup(mViewGroup));
82    }
83
84}
85