diff options
-rw-r--r-- | core/java/android/net/nsd/NsdServiceInfo.java | 3 | ||||
-rw-r--r-- | tests/net/java/android/net/nsd/NsdServiceInfoTest.java (renamed from tests/CoreTests/android/core/NsdServiceInfoTest.java) | 53 |
2 files changed, 41 insertions, 15 deletions
diff --git a/core/java/android/net/nsd/NsdServiceInfo.java b/core/java/android/net/nsd/NsdServiceInfo.java index 7b845be74921..bccaf60e697c 100644 --- a/core/java/android/net/nsd/NsdServiceInfo.java +++ b/core/java/android/net/nsd/NsdServiceInfo.java @@ -30,7 +30,6 @@ import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Map; - /** * A class representing service information for network service discovery * {@see NsdManager} @@ -43,7 +42,7 @@ public final class NsdServiceInfo implements Parcelable { private String mServiceType; - private final ArrayMap<String, byte[]> mTxtRecord = new ArrayMap<String, byte[]>(); + private final ArrayMap<String, byte[]> mTxtRecord = new ArrayMap<>(); private InetAddress mHost; diff --git a/tests/CoreTests/android/core/NsdServiceInfoTest.java b/tests/net/java/android/net/nsd/NsdServiceInfoTest.java index 5bf0167f1cf0..e48b52225c97 100644 --- a/tests/CoreTests/android/core/NsdServiceInfoTest.java +++ b/tests/net/java/android/net/nsd/NsdServiceInfoTest.java @@ -1,11 +1,32 @@ -package android.core; - -import android.test.AndroidTestCase; +/* + * Copyright (C) 2014 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.nsd; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import android.os.Bundle; import android.os.Parcel; import android.os.StrictMode; import android.net.nsd.NsdServiceInfo; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import android.util.Log; import java.util.Arrays; @@ -14,8 +35,12 @@ import java.util.Map; import java.net.InetAddress; import java.net.UnknownHostException; +import org.junit.Test; +import org.junit.runner.RunWith; -public class NsdServiceInfoTest extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +@SmallTest +public class NsdServiceInfoTest { public final static InetAddress LOCALHOST; static { @@ -30,6 +55,7 @@ public class NsdServiceInfoTest extends AndroidTestCase { LOCALHOST = _host; } + @Test public void testLimits() throws Exception { NsdServiceInfo info = new NsdServiceInfo(); @@ -85,6 +111,7 @@ public class NsdServiceInfoTest extends AndroidTestCase { assertTrue(info.getTxtRecord().length == 1300); } + @Test public void testParcel() throws Exception { NsdServiceInfo emptyInfo = new NsdServiceInfo(); checkParcelable(emptyInfo); @@ -139,25 +166,25 @@ public class NsdServiceInfoTest extends AndroidTestCase { NsdServiceInfo result = reader.getParcelable("test_info"); // Assert equality of base fields. - assertEquality(original.getServiceName(), result.getServiceName()); - assertEquality(original.getServiceType(), result.getServiceType()); - assertEquality(original.getHost(), result.getHost()); + assertEquals(original.getServiceName(), result.getServiceName()); + assertEquals(original.getServiceType(), result.getServiceType()); + assertEquals(original.getHost(), result.getHost()); assertTrue(original.getPort() == result.getPort()); // Assert equality of attribute map. Map<String, byte[]> originalMap = original.getAttributes(); Map<String, byte[]> resultMap = result.getAttributes(); - assertEquality(originalMap.keySet(), resultMap.keySet()); + assertEquals(originalMap.keySet(), resultMap.keySet()); for (String key : originalMap.keySet()) { assertTrue(Arrays.equals(originalMap.get(key), resultMap.get(key))); } } - public void assertEquality(Object expected, Object result) { - assertTrue(expected == result || expected.equals(result)); - } - public void assertEmptyServiceInfo(NsdServiceInfo shouldBeEmpty) { - assertTrue(null == shouldBeEmpty.getTxtRecord()); + byte[] txtRecord = shouldBeEmpty.getTxtRecord(); + if (txtRecord == null || txtRecord.length == 0) { + return; + } + fail("NsdServiceInfo.getTxtRecord did not return null but " + Arrays.toString(txtRecord)); } } |