blob: d0eaaf5cfc7ab93db904a7855e8d6dd81ffce7f3 [file] [log] [blame]
Adrian Roosc1b50322017-02-27 21:07:58 +01001/*
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.systemui.util.wakelock;
18
19import static junit.framework.TestCase.assertTrue;
20
21import static org.junit.Assert.assertEquals;
22import static org.junit.Assert.assertFalse;
23
Brett Chabot84151d92019-02-27 15:37:59 -080024import androidx.test.filters.SmallTest;
25import androidx.test.runner.AndroidJUnit4;
Adrian Roosc1b50322017-02-27 21:07:58 +010026
Jason Monkfba8faf2017-05-23 10:42:59 -040027import com.android.systemui.SysuiTestCase;
28
Adrian Roosc1b50322017-02-27 21:07:58 +010029import org.junit.Before;
30import org.junit.Test;
31import org.junit.runner.RunWith;
32
33@SmallTest
34@RunWith(AndroidJUnit4.class)
Jason Monkfba8faf2017-05-23 10:42:59 -040035public class SettableWakeLockTest extends SysuiTestCase {
Adrian Roosc1b50322017-02-27 21:07:58 +010036
37 private WakeLockFake mFake;
38 private SettableWakeLock mSettable;
39
40 @Before
41 public void setup() {
42 mFake = new WakeLockFake();
Lucas Dupinee4c9b72019-02-18 17:04:58 -080043 mSettable = new SettableWakeLock(mFake, "Fake");
Adrian Roosc1b50322017-02-27 21:07:58 +010044 }
45
46 @Test
47 public void setAcquire_true_acquires() throws Exception {
48 mSettable.setAcquired(true);
49 assertTrue(mFake.isHeld());
50 assertEquals(mFake.isHeld(), mSettable.isAcquired());
51 }
52
53 @Test
54 public void setAcquire_false_releases() throws Exception {
55 mSettable.setAcquired(true);
56 mSettable.setAcquired(false);
57 assertFalse(mFake.isHeld());
58 assertEquals(mFake.isHeld(), mSettable.isAcquired());
59 }
60
61 @Test
62 public void setAcquire_true_multipleTimes_isIdempotent() throws Exception {
63 mSettable.setAcquired(true);
64 mSettable.setAcquired(true);
65 mSettable.setAcquired(true);
66 mSettable.setAcquired(false);
67 assertFalse(mFake.isHeld());
68 assertEquals(mFake.isHeld(), mSettable.isAcquired());
69 }
70
71 @Test
72 public void setAcquire_false_multipleTimes_idempotent() throws Exception {
73 mSettable.setAcquired(true);
74 mSettable.setAcquired(false);
75 mSettable.setAcquired(false);
76 assertFalse(mFake.isHeld());
77 assertEquals(mFake.isHeld(), mSettable.isAcquired());
78 }
79
80 @Test
81 public void setAcquire_false_multipleTimes_idempotent_again() throws Exception {
82 mSettable.setAcquired(true);
83 mSettable.setAcquired(false);
84 mSettable.setAcquired(false);
85 mSettable.setAcquired(true);
86 assertTrue(mFake.isHeld());
87 assertEquals(mFake.isHeld(), mSettable.isAcquired());
88 }
89
90
91}