### Question:
BeaconUtil { public static Beacon getClosestBeacon(List<? extends Beacon> beaconList) { if (beaconList.isEmpty()) { return null; } return getClosestBeacon(beaconList, beaconList.get(0).createSuggestedWindowFilter()); }  static float getAdvertisingRange(int transmissionPower); static double getSmallestDistance(List<? extends Beacon> beaconList); static double getSmallestDistance(List<? extends Beacon> beaconList, WindowFilter filter); static Beacon getClosestBeacon(List<? extends Beacon> beaconList); static Beacon getClosestBeacon(List<? extends Beacon> beaconList, WindowFilter filter); static int calculateRssiForDistance(Beacon beacon, float distance); static int calculateRssi(float distance, float calibratedRssi, int calibratedDistance, float pathLossParameter); static int calculateRssi(float distance, float calibratedRssi, float pathLossParameter); static float getAdvertisingRange(int transmissionPower, int calibratedTransmissionPower, int calibratedRange); static String getReadableBeaconType(AdvertisingPacket advertisingPacket); static String getReadableBeaconType(Class<? extends Beacon> beaconClass); static Comparator<Beacon> DescendingRssiComparator; static Comparator<Beacon> AscendingRssiComparator; }### Answer:
@Test public void getClosestBeacon_noBeacon_returnsNull() { Beacon beacon = BeaconUtil.getClosestBeacon(new ArrayList<Beacon<AdvertisingPacket>>(), new KalmanFilter()); assertNull("Beacon should not be initialized", beacon); }
@Test @SuppressWarnings("unchecked") public void getClosestBeacon_singleBeacon_returnsBeacon() throws Exception { List<IBeacon> beacons = new ArrayList<>(); IBeacon<IBeaconAdvertisingPacket> expectedBeacon = beaconCreator.createBeaconWithAdvertisingPacket(2); beacons.add(expectedBeacon); IBeacon<IBeaconAdvertisingPacket> actualBeacon = (IBeacon) BeaconUtil.getClosestBeacon(beacons, new KalmanFilter(2, TimeUnit.SECONDS)); assertEquals("Did not return the only beacon added", expectedBeacon, actualBeacon); }
@Test @SuppressWarnings("unchecked") public void getClosestBeacon_multipleBeacons_returnsClosestBeacon() throws Exception { int numberOfBeaconsToUse = 5; float expectedDistance = 2; List<IBeacon> beacons = new ArrayList<>(); for (int i = 1; i < numberOfBeaconsToUse; i++) { beacons.add(beaconCreator.createBeaconWithAdvertisingPacket(expectedDistance + i)); } IBeacon<IBeaconAdvertisingPacket> expectedBeacon = beaconCreator.createBeaconWithAdvertisingPacket(expectedDistance); beacons.add(expectedBeacon); IBeacon<IBeaconAdvertisingPacket> actualBeacon = (IBeacon) BeaconUtil.getClosestBeacon(beacons, new KalmanFilter(2, TimeUnit.SECONDS)); assertEquals("Did not return the closest beacon", expectedBeacon, actualBeacon); }