GlifStyleTest.java revision 4ed1ae46ef6bb3740b8dae7d307c1fd3d136f7dc
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 com.android.setupwizardlib.util;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertNull;
21import static org.robolectric.RuntimeEnvironment.application;
22
23import android.content.Context;
24import android.os.Build.VERSION;
25import android.os.Build.VERSION_CODES;
26import android.view.ContextThemeWrapper;
27import android.widget.Button;
28
29import com.android.setupwizardlib.BuildConfig;
30import com.android.setupwizardlib.R;
31import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner;
32
33import org.junit.Before;
34import org.junit.Test;
35import org.junit.runner.RunWith;
36import org.robolectric.Robolectric;
37import org.robolectric.annotation.Config;
38
39@RunWith(SuwLibRobolectricTestRunner.class)
40@Config(constants = BuildConfig.class, sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK})
41public class GlifStyleTest {
42
43    private Context mContext;
44
45    @Before
46    public void setUp() {
47        mContext = new ContextThemeWrapper(application, R.style.SuwThemeGlif_Light);
48    }
49
50    @Test
51    public void testSuwGlifButtonTertiary() {
52        Button button = new Button(
53                mContext,
54                Robolectric.buildAttributeSet()
55                        .setStyleAttribute("@style/SuwGlifButton.Tertiary")
56                        .build());
57        assertNull("Background of tertiary button should be null", button.getBackground());
58        assertNull("Tertiary button should have no transformation method",
59                button.getTransformationMethod());
60        if (VERSION.SDK_INT < VERSION_CODES.M) {
61            // Robolectric resolved the wrong theme attribute on versions >= M
62            // https://github.com/robolectric/robolectric/issues/2940
63            assertEquals("ff4285f4", Integer.toHexString(button.getTextColors().getDefaultColor()));
64        }
65    }
66}
67