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 17 package com.android.settingslib.deviceinfo; 18 19 import static com.google.common.truth.Truth.assertWithMessage; 20 21 import static org.mockito.Mockito.doReturn; 22 23 import android.content.Context; 24 import android.net.ConnectivityManager; 25 import android.net.wifi.WifiManager; 26 import android.support.v7.preference.Preference; 27 import android.support.v7.preference.PreferenceScreen; 28 29 import com.android.settingslib.SettingsLibRobolectricTestRunner; 30 import com.android.settingslib.core.lifecycle.Lifecycle; 31 32 import org.junit.Before; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.mockito.Mock; 36 import org.mockito.MockitoAnnotations; 37 38 import java.util.Arrays; 39 import java.util.List; 40 41 @RunWith(SettingsLibRobolectricTestRunner.class) 42 public class IpAddressPreferenceControllerTest { 43 @Mock 44 private Context mContext; 45 @Mock 46 private Lifecycle mLifecycle; 47 @Mock 48 private PreferenceScreen mScreen; 49 @Mock 50 private Preference mPreference; 51 52 @Before 53 public void setUp() { 54 MockitoAnnotations.initMocks(this); 55 doReturn(mPreference).when(mScreen) 56 .findPreference(AbstractIpAddressPreferenceController.KEY_IP_ADDRESS); 57 } 58 59 @Test 60 public void testHasIntentFilters() { 61 final AbstractIpAddressPreferenceController ipAddressPreferenceController = 62 new ConcreteIpAddressPreferenceController(mContext, mLifecycle); 63 final List<String> expectedIntents = Arrays.asList( 64 ConnectivityManager.CONNECTIVITY_ACTION, 65 WifiManager.LINK_CONFIGURATION_CHANGED_ACTION, 66 WifiManager.NETWORK_STATE_CHANGED_ACTION); 67 68 69 assertWithMessage("Intent filter should contain expected intents") 70 .that(ipAddressPreferenceController.getConnectivityIntents()) 71 .asList().containsAllIn(expectedIntents); 72 } 73 74 private static class ConcreteIpAddressPreferenceController extends 75 AbstractIpAddressPreferenceController { 76 77 public ConcreteIpAddressPreferenceController(Context context, 78 Lifecycle lifecycle) { 79 super(context, lifecycle); 80 } 81 } 82 } 83