blob: 20dcbb73c2121356166d273f69b492c90034bb3b [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.testing.AndroidTestingRunner;
26import android.testing.TestableLooper;
27
Brett Chabot84151d92019-02-27 15:37:59 -080028import androidx.test.filters.SmallTest;
29
Lucas Dupin4e023812018-04-02 21:19:23 -070030import com.android.systemui.SysuiTestCase;
Jason Monka716bac2018-12-05 15:48:21 -050031import com.android.systemui.util.Assert;
Lucas Dupin4e023812018-04-02 21:19:23 -070032
33import org.junit.Before;
34import org.junit.Test;
35import org.junit.runner.RunWith;
36import org.mockito.Mock;
37import org.mockito.MockitoAnnotations;
38
39@SmallTest
Jason Monka716bac2018-12-05 15:48:21 -050040@TestableLooper.RunWithLooper
Lucas Dupin4e023812018-04-02 21:19:23 -070041@RunWith(AndroidTestingRunner.class)
42public class KeepAwakeAnimationListenerTest extends SysuiTestCase {
43 @Mock WakeLock mWakeLock;
44 KeepAwakeAnimationListener mKeepAwakeAnimationListener;
45
46 @Before
47 public void setup() {
Jason Monka716bac2018-12-05 15:48:21 -050048 Assert.sMainLooper = TestableLooper.get(this).getLooper();
Lucas Dupin4e023812018-04-02 21:19:23 -070049 MockitoAnnotations.initMocks(this);
50 KeepAwakeAnimationListener.sWakeLock = mWakeLock;
51 mKeepAwakeAnimationListener = new KeepAwakeAnimationListener(getContext());
52 }
53
54 @Test
55 public void onAnimationStart_holdsWakeLock() {
56 mKeepAwakeAnimationListener.onAnimationStart((Animator) null);
Lucas Dupinee4c9b72019-02-18 17:04:58 -080057 verify(mWakeLock).acquire(anyString());
58 verify(mWakeLock, never()).release(anyString());
Lucas Dupin4e023812018-04-02 21:19:23 -070059
60 mKeepAwakeAnimationListener.onAnimationEnd((Animator) null);
Lucas Dupinee4c9b72019-02-18 17:04:58 -080061 verify(mWakeLock).release(anyString());
Lucas Dupin4e023812018-04-02 21:19:23 -070062 }
Jason Monka716bac2018-12-05 15:48:21 -050063
64 @Test(expected = IllegalStateException.class)
65 public void initThrows_onNonMainThread() {
66 Assert.sMainLooper = Looper.getMainLooper();
67 new KeepAwakeAnimationListener(getContext());
68 }
Lucas Dupin4e023812018-04-02 21:19:23 -070069}