From da918df16e03ee19be62343313d954027d3eb3ab Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Mon, 28 Nov 2016 11:28:40 -0800 Subject: WifiServiceImpl: allow for unit tests Some structural cleanup that allows for WifiServiceImplTest development. Bug: 33167818 Test: runtests.sh Change-Id: Ic3ca545f210dfaa3277cc28166b2611b3c818408 --- .../android/server/wifi/WifiServiceImplTest.java | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java new file mode 100644 index 000000000..c5b0f8a4c --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi; + +import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.content.res.Resources; +import android.os.HandlerThread; +import android.os.test.TestLooper; +import android.test.suitebuilder.annotation.SmallTest; + +import com.android.internal.util.AsyncChannel; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Unit tests for {@link WifiServiceImpl}. + * + * Note: this is intended to build up over time and will not immediately cover the entire file. + */ +@SmallTest +public class WifiServiceImplTest { + + private static final String TAG = "WifiServiceImplTest"; + private static final int DEFAULT_VERBOSE_LOGGING = 0; + + @Mock Context mContext; + @Mock WifiInjector mWifiInjector; + WifiServiceImpl mWifiServiceImpl; + + @Mock WifiTrafficPoller mWifiTrafficPoller; + @Mock WifiStateMachine mWifiStateMachine; + @Mock HandlerThread mHandlerThread; + TestLooper mLooper; + @Mock AsyncChannel mAsyncChannel; + @Mock Resources mResources; + @Mock FrameworkFacade mFrameworkFacade; + @Mock WifiLockManager mLockManager; + @Mock WifiMulticastLockManager mWifiMulticastLockManager; + @Mock WifiLastResortWatchdog mWifiLastResortWatchdog; + @Mock WifiBackupRestore mWifiBackupRestore; + + @Before public void setUp() { + MockitoAnnotations.initMocks(this); + mLooper = new TestLooper(); + + when(mWifiInjector.getWifiStateMachine()).thenReturn(mWifiStateMachine); + when(mWifiInjector.getWifiServiceHandlerThread()).thenReturn(mHandlerThread); + when(mHandlerThread.getLooper()).thenReturn(mLooper.getLooper()); + when(mContext.getResources()).thenReturn(mResources); + when(mWifiInjector.getFrameworkFacade()).thenReturn(mFrameworkFacade); + when(mWifiInjector.getWifiLockManager()).thenReturn(mLockManager); + when(mWifiInjector.getWifiMulticastLockManager()).thenReturn(mWifiMulticastLockManager); + when(mWifiInjector.getWifiLastResortWatchdog()).thenReturn(mWifiLastResortWatchdog); + when(mWifiInjector.getWifiBackupRestore()).thenReturn(mWifiBackupRestore); + mWifiServiceImpl = new WifiServiceImpl(mContext, mWifiInjector, mAsyncChannel); + } + + @Test + public void testRemoveNetworkUnknown() { + assertFalse(mWifiServiceImpl.removeNetwork(-1)); + } + +} -- cgit v1.2.3