blob: 3f48ea7e23adb961aa8c8d93376fbb417e2e7af7 [file] [log] [blame]
Robert Snoeberger496916b2019-01-15 18:00:58 -05001/*
2 * Copyright (C) 2019 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 */
16package com.android.keyguard.clock;
17
18import static com.google.common.truth.Truth.assertThat;
19
Robert Snoeberger9ad03f42019-02-28 14:47:49 -050020import android.content.res.Resources;
Robert Snoeberger496916b2019-01-15 18:00:58 -050021import android.test.suitebuilder.annotation.SmallTest;
22import android.testing.AndroidTestingRunner;
23import android.testing.TestableLooper.RunWithLooper;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.view.ViewGroup;
27import android.widget.TextView;
28
29import com.android.systemui.SysuiTestCase;
Robert Snoeberger2ba20602019-03-29 14:25:39 -040030import com.android.systemui.colorextraction.SysuiColorExtractor;
Robert Snoeberger496916b2019-01-15 18:00:58 -050031
32import org.junit.Before;
33import org.junit.Test;
34import org.junit.runner.RunWith;
Robert Snoeberger2ba20602019-03-29 14:25:39 -040035import org.mockito.Mock;
36import org.mockito.MockitoAnnotations;
Robert Snoeberger496916b2019-01-15 18:00:58 -050037
38@SmallTest
39@RunWith(AndroidTestingRunner.class)
40@RunWithLooper
Robert Snoeberger7fd7f512019-04-12 13:46:16 -040041public final class AnalogClockControllerTest extends SysuiTestCase {
Robert Snoeberger496916b2019-01-15 18:00:58 -050042
Robert Snoeberger7fd7f512019-04-12 13:46:16 -040043 private AnalogClockController mClockController;
Robert Snoeberger2ba20602019-03-29 14:25:39 -040044 @Mock SysuiColorExtractor mMockColorExtractor;
Robert Snoeberger496916b2019-01-15 18:00:58 -050045
46 @Before
47 public void setUp() {
Robert Snoeberger2ba20602019-03-29 14:25:39 -040048 MockitoAnnotations.initMocks(this);
49
Robert Snoeberger9ad03f42019-02-28 14:47:49 -050050 Resources res = getContext().getResources();
Robert Snoeberger496916b2019-01-15 18:00:58 -050051 LayoutInflater layoutInflater = LayoutInflater.from(getContext());
Robert Snoeberger7fd7f512019-04-12 13:46:16 -040052 mClockController = new AnalogClockController(res, layoutInflater,
Robert Snoeberger2ba20602019-03-29 14:25:39 -040053 mMockColorExtractor);
Robert Snoeberger496916b2019-01-15 18:00:58 -050054 }
55
56 @Test
Robert Snoeberger69956802019-04-16 16:55:21 -040057 public void setDarkAmount_AOD() {
Robert Snoeberger496916b2019-01-15 18:00:58 -050058 ViewGroup smallClockFrame = (ViewGroup) mClockController.getView();
59 View smallClock = smallClockFrame.getChildAt(0);
60 // WHEN dark amount is set to AOD
61 mClockController.setDarkAmount(1f);
Robert Snoeberger69956802019-04-16 16:55:21 -040062 // THEN small clock should be shown.
63 assertThat(smallClock.getVisibility()).isEqualTo(View.VISIBLE);
Robert Snoeberger496916b2019-01-15 18:00:58 -050064 }
65
66 @Test
Robert Snoeberger69956802019-04-16 16:55:21 -040067 public void setColorPalette_setDigitalClock() {
Robert Snoeberger496916b2019-01-15 18:00:58 -050068 ViewGroup smallClock = (ViewGroup) mClockController.getView();
Robert Snoeberger69956802019-04-16 16:55:21 -040069 // WHEN color palette is set
70 mClockController.setColorPalette(true, new int[]{42});
Robert Snoeberger496916b2019-01-15 18:00:58 -050071 // THEN child of small clock should have text color set.
72 TextView digitalClock = (TextView) smallClock.getChildAt(0);
73 assertThat(digitalClock.getCurrentTextColor()).isEqualTo(42);
74 }
75}