1/* 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.server.wifi; 18 19import static org.mockito.Mockito.*; 20import static org.mockito.MockitoAnnotations.*; 21 22import android.test.suitebuilder.annotation.SmallTest; 23 24import org.junit.Before; 25import org.junit.Test; 26import org.mockito.Mock; 27 28/** 29 * Unit tests for {@link com.android.server.wifi.SelfRecovery}. 30 */ 31@SmallTest 32public class SelfRecoveryTest { 33 SelfRecovery mSelfRecovery; 34 @Mock WifiController mWifiController; 35 36 @Before 37 public void setUp() throws Exception { 38 initMocks(this); 39 mSelfRecovery = new SelfRecovery(mWifiController); 40 } 41 42 /** 43 * Verifies that invocations of {@link SelfRecovery#trigger(int)} with valid reasons will send 44 * the restart message to {@link WifiController}. 45 */ 46 @Test 47 public void testValidTriggerReasonsSendMessageToWifiController() { 48 mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG); 49 verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI)); 50 reset(mWifiController); 51 52 mSelfRecovery.trigger(SelfRecovery.REASON_HAL_CRASH); 53 verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI)); 54 reset(mWifiController); 55 56 mSelfRecovery.trigger(SelfRecovery.REASON_WIFICOND_CRASH); 57 verify(mWifiController).sendMessage(eq(WifiController.CMD_RESTART_WIFI)); 58 reset(mWifiController); 59 60 } 61 62 /** 63 * Verifies that invocations of {@link SelfRecovery#trigger(int)} with invalid reasons will not 64 * send the restart message to {@link WifiController}. 65 */ 66 @Test 67 public void testInvalidTriggerReasonsDoesNotSendMessageToWifiController() { 68 mSelfRecovery.trigger(-1); 69 verify(mWifiController, never()).sendMessage(anyInt()); 70 71 mSelfRecovery.trigger(8); 72 verify(mWifiController, never()).sendMessage(anyInt()); 73 } 74} 75