diff options
| author | 2017-03-14 03:02:19 +0000 | |
|---|---|---|
| committer | 2017-03-14 03:02:20 +0000 | |
| commit | db4333a2c211802eaf2ee87e5d0b76c93acd84f5 (patch) | |
| tree | a34521e3342f98f0d52385761cf06069793f121d | |
| parent | b2bb98e62dd9c7b7cad2d7d34c1865ad8590b230 (diff) | |
| parent | aa95ae57ecc5bbc461e42ca44bcc9d78537da4fe (diff) | |
Merge "Skeleton of an IpManagerTest"
| -rw-r--r-- | tests/net/java/android/net/ip/IpManagerTest.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/net/java/android/net/ip/IpManagerTest.java b/tests/net/java/android/net/ip/IpManagerTest.java new file mode 100644 index 000000000000..b04690e6519a --- /dev/null +++ b/tests/net/java/android/net/ip/IpManagerTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2017 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 android.net.ip; + +import static org.mockito.Mockito.when; + +import android.content.ContentResolver; +import android.content.Context; +import android.content.res.Resources; +import android.os.INetworkManagementService; +import android.provider.Settings; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; +import android.test.mock.MockContentResolver; + +import com.android.internal.util.test.FakeSettingsProvider; +import com.android.internal.R; + +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Tests for IpManager. + * + * @hide + */ +@RunWith(AndroidJUnit4.class) +@SmallTest +public class IpManagerTest { + @Mock private Context mContext; + @Mock private INetworkManagementService mNMService; + @Mock private Resources mResources; + private MockContentResolver mContentResolver; + + @Before public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + when(mContext.getResources()).thenReturn(mResources); + when(mResources.getInteger(R.integer.config_networkAvoidBadWifi)) + .thenReturn(0); + + mContentResolver = new MockContentResolver(); + mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider()); + when(mContext.getContentResolver()).thenReturn(mContentResolver); + } + + @Test + public void testNullCallbackDoesNotThrow() throws Exception { + final IpManager ipm = new IpManager(mContext, "lo", null, mNMService); + } + + @Test + public void testInvalidInterfaceDoesNotThrow() throws Exception { + final IpManager.Callback cb = new IpManager.Callback(); + final IpManager ipm = new IpManager(mContext, "test_wlan0", cb, mNMService); + } +} |