1 /* 2 * Copyright (C) 2016 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 android.net.wifi; 18 19 import static org.mockito.Mockito.mock; 20 import static org.mockito.Mockito.validateMockitoUsage; 21 import static org.mockito.Mockito.when; 22 23 import android.content.Context; 24 import android.os.Handler; 25 import android.os.test.TestLooper; 26 import android.test.suitebuilder.annotation.SmallTest; 27 28 import com.android.internal.util.test.BidirectionalAsyncChannelServer; 29 30 import org.junit.After; 31 import org.junit.Before; 32 import org.mockito.Mock; 33 import org.mockito.MockitoAnnotations; 34 35 36 /** 37 * Unit tests for {@link android.net.wifi.WifiScanner}. 38 */ 39 @SmallTest 40 public class WifiScannerTest { 41 @Mock 42 private Context mContext; 43 @Mock 44 private IWifiScanner mService; 45 46 private WifiScanner mWifiScanner; 47 private TestLooper mLooper; 48 private Handler mHandler; 49 50 /** 51 * Setup before tests. 52 */ 53 @Before setUp()54 public void setUp() throws Exception { 55 MockitoAnnotations.initMocks(this); 56 mLooper = new TestLooper(); 57 mHandler = mock(Handler.class); 58 BidirectionalAsyncChannelServer server = new BidirectionalAsyncChannelServer( 59 mContext, mLooper.getLooper(), mHandler); 60 when(mService.getMessenger()).thenReturn(server.getMessenger()); 61 mWifiScanner = new WifiScanner(mContext, mService, mLooper.getLooper()); 62 mLooper.dispatchAll(); 63 } 64 65 /** 66 * Clean up after tests. 67 */ 68 @After cleanup()69 public void cleanup() { 70 validateMockitoUsage(); 71 } 72 73 } 74