blob: 0792a05ce6bc0cd0c55e3a061be52b88fce5f06b [file] [log] [blame]
Lucas Dupin4e023812018-04-02 21:19:23 -07001/*
2 * Copyright (C) 2018 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.systemui.util.wakelock;
18
Lucas Dupinee4c9b72019-02-18 17:04:58 -080019import static org.mockito.ArgumentMatchers.anyString;
Lucas Dupin4e023812018-04-02 21:19:23 -070020import static org.mockito.Mockito.never;
21import static org.mockito.Mockito.verify;
22
23import android.animation.Animator;
Jason Monka716bac2018-12-05 15:48:21 -050024import android.os.Looper;
Lucas Dupin4e023812018-04-02 21:19:23 -070025import android.support.test.filters.SmallTest;
26import android.testing.AndroidTestingRunner;
27import android.testing.TestableLooper;
28
29import com.android.systemui.SysuiTestCase;
Jason Monka716bac2018-12-05 15:48:21 -050030import com.android.systemui.util.Assert;
Lucas Dupin4e023812018-04-02 21:19:23 -070031
32import org.junit.Before;
33import org.junit.Test;
34import org.junit.runner.RunWith;
35import org.mockito.Mock;
36import org.mockito.MockitoAnnotations;
37
38@SmallTest
Jason Monka716bac2018-12-05 15:48:21 -050039@TestableLooper.RunWithLooper
Lucas Dupin4e023812018-04-02 21:19:23 -070040@RunWith(AndroidTestingRunner.class)
41public class KeepAwakeAnimationListenerTest extends SysuiTestCase {
42 @Mock WakeLock mWakeLock;
43 KeepAwakeAnimationListener mKeepAwakeAnimationListener;
44
45 @Before
46 public void setup() {
Jason Monka716bac2018-12-05 15:48:21 -050047 Assert.sMainLooper = TestableLooper.get(this).getLooper();
Lucas Dupin4e023812018-04-02 21:19:23 -070048 MockitoAnnotations.initMocks(this);
49 KeepAwakeAnimationListener.sWakeLock = mWakeLock;
50 mKeepAwakeAnimationListener = new KeepAwakeAnimationListener(getContext());
51 }
52
53 @Test
54 public void onAnimationStart_holdsWakeLock() {
55 mKeepAwakeAnimationListener.onAnimationStart((Animator) null);
Lucas Dupinee4c9b72019-02-18 17:04:58 -080056 verify(mWakeLock).acquire(anyString());
57 verify(mWakeLock, never()).release(anyString());
Lucas Dupin4e023812018-04-02 21:19:23 -070058
59 mKeepAwakeAnimationListener.onAnimationEnd((Animator) null);
Lucas Dupinee4c9b72019-02-18 17:04:58 -080060 verify(mWakeLock).release(anyString());
Lucas Dupin4e023812018-04-02 21:19:23 -070061 }
Jason Monka716bac2018-12-05 15:48:21 -050062
63 @Test(expected = IllegalStateException.class)
64 public void initThrows_onNonMainThread() {
65 Assert.sMainLooper = Looper.getMainLooper();
66 new KeepAwakeAnimationListener(getContext());
67 }
Lucas Dupin4e023812018-04-02 21:19:23 -070068}