### Question:
PillPeripheral implements Serializable { @Nullable public static PillPeripheral getClosestByRssi(@NonNull final List<GattPeripheral> peripherals){ if(peripherals.isEmpty()){ return null; } Collections.sort(peripherals, (current, other) -> Integer.compare(other.getScanTimeRssi(), current.getScanTimeRssi())); return new PillPeripheral(peripherals.get(0)); } PillPeripheral(@NonNull final GattPeripheral gattPeripheral); static boolean isPillDfu(@Nullable final AdvertisingData advertisingData); static boolean isPillNormal(@Nullable final AdvertisingData advertisingData); static boolean isPillOneFive(@Nullable final AdvertisingData advertisingData); @Nullable static PillPeripheral getClosestByRssi(@NonNull final List<GattPeripheral> peripherals); Observable<PillPeripheral> clearCache(@NonNull final Context context); int getScanTimeRssi(); String getAddress(); String getName(); boolean isTooFar(); boolean isConnected(); @NonNull Observable<PillPeripheral> enterDfuMode(@NonNull final Context context, @NonNull final DfuCallback callback); Observable<PillPeripheral> disconnect(); @NonNull Observable<PillPeripheral> connect(); @NonNull Observable<PillPeripheral> removeBond(); Observable<PillPeripheral> wipeFirmware(); static final byte[] NORMAL_ADVERTISEMENT_SERVICE_128_BIT; static final byte[] DFU_ADVERTISEMENT_SERVICE_128_BIT; static final byte[] MANUFACTURE_DATA_PILL_ONE_FIVE_PREFIX; }### Answer:
@Test public void getClosestByRssi() throws Exception { final GattPeripheral weakerRssiPeripheral = mock(GattPeripheral.class); doReturn(-81) .when(weakerRssiPeripheral) .getScanTimeRssi(); final GattPeripheral strongerRssiPeripheral = mock(GattPeripheral.class); doReturn(-80) .when(strongerRssiPeripheral) .getScanTimeRssi(); final List<GattPeripheral> unSortedPeripherals = new ArrayList<>(2); unSortedPeripherals.add(weakerRssiPeripheral); unSortedPeripherals.add(strongerRssiPeripheral); assertEquals(unSortedPeripherals.get(0), weakerRssiPeripheral); final PillPeripheral returnedPillPeripheral = PillPeripheral.getClosestByRssi(unSortedPeripherals); assertNotNull(returnedPillPeripheral); assertEquals(strongerRssiPeripheral.getScanTimeRssi(), returnedPillPeripheral.getScanTimeRssi()); }