Bill Lin | 32ed3d6 | 2018-10-02 18:10:09 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.power; |
| 18 | |
| 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import static org.mockito.Mockito.spy; |
| 22 | import static org.mockito.Mockito.verify; |
| 23 | |
| 24 | import android.test.suitebuilder.annotation.SmallTest; |
| 25 | import android.testing.AndroidTestingRunner; |
| 26 | import android.testing.TestableLooper.RunWithLooper; |
| 27 | |
| 28 | import com.android.systemui.SysuiTestCase; |
| 29 | |
| 30 | import org.junit.After; |
| 31 | import org.junit.Before; |
| 32 | import org.junit.Test; |
| 33 | import org.junit.runner.RunWith; |
| 34 | |
| 35 | @RunWith(AndroidTestingRunner.class) |
| 36 | @RunWithLooper |
| 37 | @SmallTest |
| 38 | public class OverheatAlarmControllerTest extends SysuiTestCase{ |
| 39 | OverheatAlarmController mOverheatAlarmController; |
| 40 | OverheatAlarmController mSpyOverheatAlarmController; |
| 41 | |
| 42 | @Before |
| 43 | public void setUp() { |
| 44 | mOverheatAlarmController = OverheatAlarmController.getInstance(mContext); |
| 45 | mSpyOverheatAlarmController = spy(mOverheatAlarmController); |
| 46 | } |
| 47 | |
| 48 | @After |
| 49 | public void tearDown() { |
| 50 | mSpyOverheatAlarmController.stopAlarm(); |
| 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void testGetInstance() { |
| 55 | assertThat(mOverheatAlarmController).isNotNull(); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void testStartAlarm_PlaySound() { |
| 60 | mSpyOverheatAlarmController.startAlarm(mContext); |
| 61 | verify(mSpyOverheatAlarmController).playSound(mContext); |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | public void testStartAlarm_InitVibrate() { |
| 66 | mSpyOverheatAlarmController.startAlarm(mContext); |
| 67 | verify(mSpyOverheatAlarmController).startVibrate(); |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void testStartAlarm_StartVibrate() { |
| 72 | mSpyOverheatAlarmController.startAlarm(mContext); |
| 73 | verify(mSpyOverheatAlarmController).performVibrate(); |
| 74 | } |
| 75 | |
| 76 | @Test |
| 77 | public void testStopAlarm_StopPlayer() { |
| 78 | mSpyOverheatAlarmController.stopAlarm(); |
| 79 | verify(mSpyOverheatAlarmController).stopPlayer(); |
| 80 | } |
| 81 | |
| 82 | @Test |
| 83 | public void testStopAlarm_StopVibrate() { |
| 84 | mSpyOverheatAlarmController.stopAlarm(); |
| 85 | verify(mSpyOverheatAlarmController).stopVibrate(); |
| 86 | } |
| 87 | } |