### Question:
DistinctPacketDetector { public boolean isPacketDistinct(@NonNull String originMacAddress, @NonNull byte[] scanRecord) { byte[] macBytes = originMacAddress.getBytes(); ByteBuffer buffer = ByteBuffer.allocate(macBytes.length+scanRecord.length); buffer.put(macBytes); buffer.put(scanRecord); buffer.rewind(); if (mDistinctPacketsDetected.size() == MAX_PACKETS_TO_TRACK) { return mDistinctPacketsDetected.contains(buffer); } else { return mDistinctPacketsDetected.add(buffer); } }  void clearDetections(); boolean isPacketDistinct(@NonNull String originMacAddress, @NonNull byte[] scanRecord);  }### Answer:
@Test public void testSecondDuplicatePacketIsNotDistinct() throws Exception { DistinctPacketDetector dpd = new DistinctPacketDetector(); dpd.isPacketDistinct("01:02:03:04:05:06", new byte[] {0x01, 0x02}); boolean secondResult = dpd.isPacketDistinct("01:02:03:04:05:06", new byte[] {0x01, 0x02}); assertFalse("second call with same packet should not be distinct", secondResult); }
@Test public void testSecondNonDuplicatePacketIsDistinct() throws Exception { DistinctPacketDetector dpd = new DistinctPacketDetector(); dpd.isPacketDistinct("01:02:03:04:05:06", new byte[] {0x01, 0x02}); boolean secondResult = dpd.isPacketDistinct("01:02:03:04:05:06", new byte[] {0x03, 0x04}); assertTrue("second call with different packet should be distinct", secondResult); }
@Test public void testSamePacketForDifferentMacIsDistinct() throws Exception { DistinctPacketDetector dpd = new DistinctPacketDetector(); dpd.isPacketDistinct("01:02:03:04:05:06", new byte[] {0x01, 0x02}); boolean secondResult = dpd.isPacketDistinct("01:01:01:01:01:01", new byte[] {0x01, 0x02}); assertTrue("second packet with different mac should be distinct", secondResult); }