1 /* 2 * Copyright (C) 2018 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.util; 18 19 import static junit.framework.Assert.assertEquals; 20 import static junit.framework.Assert.assertFalse; 21 import static junit.framework.Assert.assertTrue; 22 23 import androidx.test.filters.SmallTest; 24 import androidx.test.runner.AndroidJUnit4; 25 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 @RunWith(AndroidJUnit4.class) 30 @SmallTest 31 public class InterfaceSetTest { 32 @Test testNullNamesIgnored()33 public void testNullNamesIgnored() { 34 final InterfaceSet set = new InterfaceSet(null, "if1", null, "if2", null); 35 assertEquals(2, set.ifnames.size()); 36 assertTrue(set.ifnames.contains("if1")); 37 assertTrue(set.ifnames.contains("if2")); 38 } 39 40 @Test testToString()41 public void testToString() { 42 final InterfaceSet set = new InterfaceSet("if1", "if2"); 43 final String setString = set.toString(); 44 assertTrue(setString.equals("[if1,if2]") || setString.equals("[if2,if1]")); 45 } 46 47 @Test testToString_Empty()48 public void testToString_Empty() { 49 final InterfaceSet set = new InterfaceSet(null, null); 50 assertEquals("[]", set.toString()); 51 } 52 53 @Test testEquals()54 public void testEquals() { 55 assertEquals(new InterfaceSet(null, "if1", "if2"), new InterfaceSet("if2", "if1")); 56 assertEquals(new InterfaceSet(null, null), new InterfaceSet()); 57 assertFalse(new InterfaceSet("if1", "if3").equals(new InterfaceSet("if1", "if2"))); 58 assertFalse(new InterfaceSet("if1", "if2").equals(new InterfaceSet("if1"))); 59 assertFalse(new InterfaceSet().equals(null)); 60 } 61 } 62