Add unit tests
Test: unit test
Bug: 235406470
Ignore-AOSP-First: nearby_not_in_aosp_yet
Change-Id: Iefb376333565e3251e4d94c0eb5c59cc06a3e9ce
diff --git a/nearby/service/java/com/android/server/nearby/common/bluetooth/fastpair/Bytes.java b/nearby/service/java/com/android/server/nearby/common/bluetooth/fastpair/Bytes.java
index 637cd03..f6e77e6 100644
--- a/nearby/service/java/com/android/server/nearby/common/bluetooth/fastpair/Bytes.java
+++ b/nearby/service/java/com/android/server/nearby/common/bluetooth/fastpair/Bytes.java
@@ -17,6 +17,7 @@
package com.android.server.nearby.common.bluetooth.fastpair;
import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -51,7 +52,8 @@
return this.mByteOrder.equals(byteOrder) ? getBytes() : reverse(getBytes());
}
- private static byte[] reverse(byte[] bytes) {
+ @VisibleForTesting
+ static byte[] reverse(byte[] bytes) {
byte[] reversedBytes = new byte[bytes.length];
for (int i = 0; i < bytes.length; i++) {
reversedBytes[i] = bytes[bytes.length - i - 1];
diff --git a/nearby/service/java/com/android/server/nearby/common/bluetooth/fastpair/FastPairDualConnection.java b/nearby/service/java/com/android/server/nearby/common/bluetooth/fastpair/FastPairDualConnection.java
index 789ef59..60afa31 100644
--- a/nearby/service/java/com/android/server/nearby/common/bluetooth/fastpair/FastPairDualConnection.java
+++ b/nearby/service/java/com/android/server/nearby/common/bluetooth/fastpair/FastPairDualConnection.java
@@ -1993,7 +1993,8 @@
return getLeState(bluetoothAdapter);
}
- private static int getLeState(android.bluetooth.BluetoothAdapter adapter) {
+ @VisibleForTesting
+ static int getLeState(android.bluetooth.BluetoothAdapter adapter) {
try {
return (Integer) Reflect.on(adapter).withMethod("getLeState").get();
} catch (ReflectionException e) {
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/DataElementTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/DataElementTest.java
index ec6e89a..6a5652b 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/DataElementTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/DataElementTest.java
@@ -63,4 +63,19 @@
assertThat(elementFromParcel.getKey()).isEqualTo(KEY);
assertThat(Arrays.equals(elementFromParcel.getValue(), VALUE)).isTrue();
}
+
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void describeContents() {
+ DataElement dataElement = new DataElement(KEY, VALUE);
+ assertThat(dataElement.describeContents()).isEqualTo(0);
+ }
+
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void testCreatorNewArray() {
+ DataElement[] elements =
+ DataElement.CREATOR.newArray(2);
+ assertThat(elements.length).isEqualTo(2);
+ }
}
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyDeviceTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyDeviceTest.java
index 998714c..de27879 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyDeviceTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyDeviceTest.java
@@ -88,6 +88,7 @@
assertThat(fastPairDevice1.equals(fastPairDevice1)).isTrue();
assertThat(fastPairDevice1.equals(fastPairDevice2)).isFalse();
+ assertThat(fastPairDevice1.equals(null)).isFalse();
assertThat(fastPairDevice1.hashCode()).isEqualTo(fastPairDevice2.hashCode());
}
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/PublicCredentialTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/PublicCredentialTest.java
index 05a4598..774e897 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/PublicCredentialTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/PublicCredentialTest.java
@@ -135,6 +135,7 @@
.setIdentityType(IDENTITY_TYPE_PRIVATE)
.build();
assertThat(credentialOne.equals((Object) credentialTwo)).isTrue();
+ assertThat(credentialOne.equals(null)).isFalse();
}
@Test
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/ble/BleSightingTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/ble/BleSightingTest.java
index b318842..d259851 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/ble/BleSightingTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/ble/BleSightingTest.java
@@ -110,7 +110,6 @@
Parcel dest = Parcel.obtain();
sighting.writeToParcel(dest, 0);
dest.setDataPosition(0);
- BleSighting compareSighting = BleSighting.CREATOR.createFromParcel(dest);
assertThat(sighting.getRssi()).isEqualTo(RSSI);
}
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bloomfilter/FastPairBloomFilterHasherTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bloomfilter/FastPairBloomFilterHasherTest.java
index 0923b95..92c3b1a 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bloomfilter/FastPairBloomFilterHasherTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bloomfilter/FastPairBloomFilterHasherTest.java
@@ -25,7 +25,6 @@
import java.nio.charset.Charset;
public class FastPairBloomFilterHasherTest {
- private static final int BYTE_ARRAY_LENGTH = 100;
private static final Charset CHARSET = UTF_8;
private static FastPairBloomFilterHasher sFastPairBloomFilterHasher =
new FastPairBloomFilterHasher();
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/BytesTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/BytesTest.java
index 2e46ef9..9450d60 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/BytesTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/BytesTest.java
@@ -56,4 +56,9 @@
public void testToString() {
assertThat(VALUE1.toString()).isEqualTo("0102");
}
+
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void testReverse() {
+ assertThat(VALUE1.reverse(new byte[]{1, 2})).isEqualTo(new byte[]{2, 1});
+ }
}
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/FastPairDualConnectionTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/FastPairDualConnectionTest.java
index a103a72..63c39b2 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/FastPairDualConnectionTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/FastPairDualConnectionTest.java
@@ -23,9 +23,11 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyShort;
import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -45,6 +47,7 @@
import junit.framework.TestCase;
+import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -75,6 +78,8 @@
private TestEventLogger mEventLogger;
@Mock private TimingLogger mTimingLogger;
@Mock private BluetoothAudioPairer mBluetoothAudioPairer;
+ @Mock private android.bluetooth.BluetoothAdapter mBluetoothAdapter;
+ @Mock FastPairDualConnection mFastPairDualConnection;
@Override
public void setUp() throws Exception {
@@ -287,6 +292,23 @@
}
}
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void testReflectionException()
+ throws BluetoothException, ReflectionException, ExecutionException,
+ InterruptedException, PairingException, TimeoutException {
+ when(mFastPairDualConnection.pair())
+ .thenThrow(new ReflectionException(
+ new NoSuchMethodException("testReflectionException")));
+ ReflectionException exception =
+ assertThrows(
+ ReflectionException.class,
+ () -> mFastPairDualConnection.pair());
+ assertThat(exception)
+ .hasMessageThat()
+ .contains("testReflectionException");
+ }
+
@SdkSuppress(minSdkVersion = 32, codeName = "T")
public void testHistoryItem() {
FastPairDualConnection connection = new FastPairDualConnection(
@@ -307,6 +329,11 @@
.isFalse();
}
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void testGetLeState() throws ReflectionException {
+ FastPairDualConnection.getLeState(mBluetoothAdapter);
+ }
+
static class TestEventLogger implements EventLogger {
private List<Item> mLogs = new ArrayList<>();
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/HeadsetPieceTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/HeadsetPieceTest.java
index 670b2ca..32e62a3 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/HeadsetPieceTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/HeadsetPieceTest.java
@@ -196,5 +196,63 @@
assertThat(headsetPiece.isBatteryLow()).isFalse();
}
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void describeContents() {
+ HeadsetPiece headsetPiece =
+ HeadsetPiece.builder()
+ .setLowLevelThreshold(30)
+ .setBatteryLevel(18)
+ .setImageUrl("http://fake.image.path/image.png")
+ .setCharging(true)
+ .build();
+ assertThat(headsetPiece.describeContents()).isEqualTo(0);
+ }
+
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void hashcode() {
+ HeadsetPiece headsetPiece =
+ HeadsetPiece.builder()
+ .setLowLevelThreshold(30)
+ .setBatteryLevel(18)
+ .setImageUrl("http://fake.image.path/image.png")
+ .setCharging(true)
+ .build();
+ HeadsetPiece headsetPiece1 =
+ HeadsetPiece.builder()
+ .setLowLevelThreshold(30)
+ .setBatteryLevel(18)
+ .setImageUrl("http://fake.image.path/image.png")
+ .setCharging(true)
+ .build();
+ assertThat(headsetPiece.hashCode()).isEqualTo(headsetPiece1.hashCode());
+ }
+
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void testToString() {
+ HeadsetPiece headsetPiece =
+ HeadsetPiece.builder()
+ .setLowLevelThreshold(30)
+ .setBatteryLevel(18)
+ .setImageUrl("http://fake.image.path/image.png")
+ .setCharging(true)
+ .build();
+ assertThat(headsetPiece.toString())
+ .isEqualTo("HeadsetPiece{lowLevelThreshold=30,"
+ + " batteryLevel=18,"
+ + " imageUrl=http://fake.image.path/image.png,"
+ + " charging=true,"
+ + " imageContentUri=null}");
+ }
+
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void testCreatorNewArray() {
+ HeadsetPiece[] headsetPieces =
+ HeadsetPiece.CREATOR.newArray(2);
+ assertThat(headsetPieces.length).isEqualTo(2);
+ }
}
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/PairingProgressListenerTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/PairingProgressListenerTest.java
new file mode 100644
index 0000000..a58a92d
--- /dev/null
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/PairingProgressListenerTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2022 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 com.android.server.nearby.common.bluetooth.fastpair;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import org.junit.Test;
+
+public class PairingProgressListenerTest {
+
+ @Test
+ public void testFromOrdinal() {
+ assertThat(PairingProgressListener.fromOrdinal(0)).isEqualTo(
+ PairingProgressListener.PairingEvent.START);
+ assertThat(PairingProgressListener.fromOrdinal(1)).isEqualTo(
+ PairingProgressListener.PairingEvent.SUCCESS);
+ assertThat(PairingProgressListener.fromOrdinal(2)).isEqualTo(
+ PairingProgressListener.PairingEvent.FAILED);
+ assertThat(PairingProgressListener.fromOrdinal(3)).isEqualTo(
+ PairingProgressListener.PairingEvent.UNKNOWN);
+ assertThat(PairingProgressListener.fromOrdinal(4)).isEqualTo(
+ PairingProgressListener.PairingEvent.UNKNOWN);
+ }
+}
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/PreferencesTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/PreferencesTest.java
index b40a5a5..378e3b9 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/PreferencesTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/PreferencesTest.java
@@ -1266,12 +1266,38 @@
public void testExtraLoggingInformation() {
Preferences prefs =
Preferences.builder().setExtraLoggingInformation(FIRST_EXTRA_LOGGING_INFO).build();
- assertThat(prefs.getExtraLoggingInformation()).isEqualTo(FIRST_EXTRA_LOGGING_INFO);
- assertThat(prefs.toBuilder().build().getExtraLoggingInformation())
- .isEqualTo(FIRST_EXTRA_LOGGING_INFO);
-
Preferences prefs2 =
Preferences.builder().setExtraLoggingInformation(SECOND_EXTRA_LOGGING_INFO).build();
+ Preferences prefs3 =
+ Preferences.builder().setExtraLoggingInformation(FIRST_EXTRA_LOGGING_INFO).build();
+
+ assertThat(prefs.getExtraLoggingInformation()).isEqualTo(FIRST_EXTRA_LOGGING_INFO);
assertThat(prefs2.getExtraLoggingInformation()).isEqualTo(SECOND_EXTRA_LOGGING_INFO);
+ assertThat(prefs.toBuilder().build().getExtraLoggingInformation())
+ .isEqualTo(FIRST_EXTRA_LOGGING_INFO);
+ // Test equal()
+ assertThat(prefs.getExtraLoggingInformation().equals(null)).isFalse();
+ assertThat(prefs.getExtraLoggingInformation()
+ .equals(prefs2.getExtraLoggingInformation())).isFalse();
+ assertThat(prefs.getExtraLoggingInformation()
+ .equals(prefs3.getExtraLoggingInformation())).isTrue();
+ // Test getModelId()
+ assertThat(prefs.getExtraLoggingInformation().getModelId())
+ .isEqualTo(prefs3.getExtraLoggingInformation().getModelId());
+ assertThat(prefs.getExtraLoggingInformation().getModelId())
+ .isNotEqualTo(prefs2.getExtraLoggingInformation().getModelId());
+ // Test hashCode()
+ assertThat(prefs.getExtraLoggingInformation().hashCode())
+ .isEqualTo(prefs3.getExtraLoggingInformation().hashCode());
+ assertThat(prefs.getExtraLoggingInformation().hashCode())
+ .isNotEqualTo(prefs2.getExtraLoggingInformation().hashCode());
+ // Test toBuilder()
+
+ assertThat(prefs.getExtraLoggingInformation()
+ .toBuilder().setModelId("000007").build().getModelId())
+ .isEqualTo("000007");
+ // Test toString()
+ assertThat(prefs.getExtraLoggingInformation().toString())
+ .isEqualTo("ExtraLoggingInformation{modelId=000006}");
}
}
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/TdsExceptionTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/TdsExceptionTest.java
new file mode 100644
index 0000000..e8b9480
--- /dev/null
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/fastpair/TdsExceptionTest.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2022 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 com.android.server.nearby.common.bluetooth.fastpair;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.android.server.nearby.intdefs.FastPairEventIntDefs;
+
+import org.junit.Test;
+
+public class TdsExceptionTest {
+ @Test
+ public void testGetErrorCode() {
+ TdsException tdsException = new TdsException(
+ FastPairEventIntDefs.BrEdrHandoverErrorCode.BLUETOOTH_MAC_INVALID, "format");
+ assertThat(tdsException.getErrorCode())
+ .isEqualTo(FastPairEventIntDefs.BrEdrHandoverErrorCode.BLUETOOTH_MAC_INVALID);
+
+ }
+}
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothAdapterTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothAdapterTest.java
index 6ebe373..a9ab7da 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothAdapterTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothAdapterTest.java
@@ -81,6 +81,8 @@
public void testEnable_callsWrapped() {
when(mBluetoothAdapter.enable()).thenReturn(true);
assertThat(mTestabilityBluetoothAdapter.enable()).isTrue();
+ when(mBluetoothAdapter.isEnabled()).thenReturn(true);
+ assertThat(mTestabilityBluetoothAdapter.isEnabled()).isTrue();
}
@Test
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothDeviceTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothDeviceTest.java
index a962b16..d494024 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothDeviceTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothDeviceTest.java
@@ -83,6 +83,13 @@
@Test
@SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void testHashCode_asExpected() {
+ assertThat(mTestabilityBluetoothDevice.hashCode())
+ .isEqualTo(BluetoothDevice.wrap(mBluetoothDevice).hashCode());
+ }
+
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
public void testConnectGattWithThreeParameters_callsWrapped() {
when(mBluetoothDevice
.connectGatt(mContext, true, mTestBluetoothGattCallback.unwrap()))
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothGattWrapperTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothGattWrapperTest.java
index 199146d..a03a255 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothGattWrapperTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/testability/android/bluetooth/BluetoothGattWrapperTest.java
@@ -84,6 +84,12 @@
}
@Test
+ public void testHashCode_asExpected() {
+ assertThat(mBluetoothGattWrapper.hashCode())
+ .isEqualTo(BluetoothGattWrapper.wrap(mBluetoothGatt).hashCode());
+ }
+
+ @Test
@SdkSuppress(minSdkVersion = 32, codeName = "T")
public void testGetServices_callsWrapped() {
when(mBluetoothGatt.getServices()).thenReturn(null);
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/util/BluetoothGattUtilsTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/util/BluetoothGattUtilsTest.java
index 47182c3..7535c06 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/util/BluetoothGattUtilsTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/bluetooth/util/BluetoothGattUtilsTest.java
@@ -34,14 +34,12 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
-import java.util.UUID;
/** Unit tests for {@link BluetoothGattUtils}. */
@Presubmit
@SmallTest
@RunWith(AndroidJUnit4.class)
public class BluetoothGattUtilsTest {
- private static final UUID TEST_UUID = UUID.randomUUID();
private static final ImmutableSet<String> GATT_HIDDEN_CONSTANTS = ImmutableSet.of(
"GATT_WRITE_REQUEST_BUSY", "GATT_WRITE_REQUEST_FAIL", "GATT_WRITE_REQUEST_SUCCESS");
diff --git a/nearby/tests/unit/src/com/android/server/nearby/common/eventloop/HandlerEventLoopImplTest.java b/nearby/tests/unit/src/com/android/server/nearby/common/eventloop/HandlerEventLoopImplTest.java
index 6b5eaa8..4775456 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/common/eventloop/HandlerEventLoopImplTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/common/eventloop/HandlerEventLoopImplTest.java
@@ -67,6 +67,12 @@
assertThat(mExecutedRunnables).isEmpty();
}
+ @Test
+ @SdkSuppress(minSdkVersion = 32, codeName = "T")
+ public void postEmptyQueueRunnable() {
+ mHandlerEventLoopImpl.postEmptyQueueRunnable(
+ new HandlerEventLoopImplTest.NumberedRunnable(0));
+ }
private class NumberedRunnable extends NamedRunnable {
private final int mId;
diff --git a/nearby/tests/unit/src/com/android/server/nearby/fastpair/FastPairAdvHandlerTest.java b/nearby/tests/unit/src/com/android/server/nearby/fastpair/FastPairAdvHandlerTest.java
index 01f2f46..39ea5a9 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/fastpair/FastPairAdvHandlerTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/fastpair/FastPairAdvHandlerTest.java
@@ -23,7 +23,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import android.accounts.Account;
import android.content.Context;
import android.nearby.FastPairDevice;
@@ -69,7 +68,6 @@
private static final int TX_POWER = -70;
private static final byte[] INITIAL_BYTE_ARRAY = new byte[]{0x01, 0x02, 0x03};
private static final byte[] SALT = new byte[]{0x01};
- private static final Account ACCOUNT = new Account("abc@google.com", "type1");
LocatorContextWrapper mLocatorContextWrapper;
FastPairAdvHandler mFastPairAdvHandler;
diff --git a/nearby/tests/unit/src/com/android/server/nearby/fastpair/cache/FastPairCacheManagerTest.java b/nearby/tests/unit/src/com/android/server/nearby/fastpair/cache/FastPairCacheManagerTest.java
index 0f6fb19..075699e 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/fastpair/cache/FastPairCacheManagerTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/fastpair/cache/FastPairCacheManagerTest.java
@@ -44,7 +44,6 @@
private static final ByteString ACCOUNT_KEY = ByteString.copyFromUtf8("axgs");
private static final String MAC_ADDRESS_B = "00:11:22:44";
private static final ByteString ACCOUNT_KEY_B = ByteString.copyFromUtf8("axgb");
- private static final String ITEM_ID = "ITEM_ID";
@Mock
DiscoveryItem mDiscoveryItem;
diff --git a/nearby/tests/unit/src/com/android/server/nearby/provider/ChreCommunicationTest.java b/nearby/tests/unit/src/com/android/server/nearby/provider/ChreCommunicationTest.java
index c90860e..7542d53 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/provider/ChreCommunicationTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/provider/ChreCommunicationTest.java
@@ -113,14 +113,45 @@
@Test
public void testContextHubTransactionResultToString() {
- NanoAppMessage message =
- NanoAppMessage.createMessageToNanoApp(
- ChreDiscoveryProvider.NANOAPP_ID,
- ChreDiscoveryProvider.NANOAPP_MESSAGE_TYPE_FILTER_RESULT,
- new byte[] {1, 2, 3});
assertThat(
mChreCommunication.contextHubTransactionResultToString(
- mClient.sendMessageToNanoApp(message))).isEqualTo("RESULT_SUCCESS");
+ ContextHubTransaction.RESULT_SUCCESS))
+ .isEqualTo("RESULT_SUCCESS");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(
+ ContextHubTransaction.RESULT_FAILED_UNKNOWN))
+ .isEqualTo("RESULT_FAILED_UNKNOWN");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(
+ ContextHubTransaction.RESULT_FAILED_BAD_PARAMS))
+ .isEqualTo("RESULT_FAILED_BAD_PARAMS");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(
+ ContextHubTransaction.RESULT_FAILED_UNINITIALIZED))
+ .isEqualTo("RESULT_FAILED_UNINITIALIZED");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(
+ ContextHubTransaction.RESULT_FAILED_BUSY))
+ .isEqualTo("RESULT_FAILED_BUSY");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(
+ ContextHubTransaction.RESULT_FAILED_AT_HUB))
+ .isEqualTo("RESULT_FAILED_AT_HUB");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(
+ ContextHubTransaction.RESULT_FAILED_TIMEOUT))
+ .isEqualTo("RESULT_FAILED_TIMEOUT");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(
+ ContextHubTransaction.RESULT_FAILED_SERVICE_INTERNAL_FAILURE))
+ .isEqualTo("RESULT_FAILED_SERVICE_INTERNAL_FAILURE");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(
+ ContextHubTransaction.RESULT_FAILED_HAL_UNAVAILABLE))
+ .isEqualTo("RESULT_FAILED_HAL_UNAVAILABLE");
+ assertThat(
+ mChreCommunication.contextHubTransactionResultToString(9))
+ .isEqualTo("UNKNOWN_RESULT value=9");
}
@Test
diff --git a/nearby/tests/unit/src/com/android/server/nearby/util/identity/CallerIdentityTest.java b/nearby/tests/unit/src/com/android/server/nearby/util/identity/CallerIdentityTest.java
index a18aa1f..c29cb92 100644
--- a/nearby/tests/unit/src/com/android/server/nearby/util/identity/CallerIdentityTest.java
+++ b/nearby/tests/unit/src/com/android/server/nearby/util/identity/CallerIdentityTest.java
@@ -33,4 +33,13 @@
assertThat(callerIdentity.toString()).isEqualTo("100/package_name[attribution_tag]");
assertThat(callerIdentity.isSystemServer()).isFalse();
}
+
+ @Test
+ public void testHashCode() {
+ CallerIdentity callerIdentity =
+ CallerIdentity.forTest(UID, PID, PACKAGE_NAME, ATTRIBUTION_TAG);
+ CallerIdentity callerIdentity1 =
+ CallerIdentity.forTest(UID, PID, PACKAGE_NAME, ATTRIBUTION_TAG);
+ assertThat(callerIdentity.hashCode()).isEqualTo(callerIdentity1.hashCode());
+ }
}