@Test public void testScannerEvictsOutdatedBeacons() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { final long beaconExpirationDurationSeconds = 10; final long scanRestDurationSeconds = 6; final ScanDuration scanDuration = preciseDuration( SECONDS.toMillis(scanRestDurationSeconds), SECONDS.toMillis(scanRestDurationSeconds) ); final BeaconScanner scanner = new BeaconScanner .Builder(ApplicationProvider.getApplicationContext()) .setBleDevice(bleDevice) .setBeaconBatchListener(beaconListener) .setBeaconExpirationDuration(beaconExpirationDurationSeconds) .setScanDuration(scanDuration) .setTimeProvider(timeProvider) .setScanTasksExecutor(executorProvider) .build(); final ScanResult scanResult = getScanResult(); scanner.start(); advanceTimeBy(10); bleDevice.transmitScanResult(scanResult); advanceTimeBy(20); assertEquals( singleton( new Beacon( bluetoothAddress, asList(48812, fromString(proximityUuid), major, minor, txPower, data), txPower ) ), beaconListener.nearbyBeacons ); advanceTimeBy(7_000); assertThat( beaconListener.nearbyBeacons, not(is(Matchers.<Beacon>empty())) ); advanceTimeBy(4_000); assertEquals( Collections.<Beacon>emptySet(), beaconListener.nearbyBeacons ); }
@Override public void start() { scheduledExecutor.schedule( scanResumeJob, 0L, TimeUnit.MILLISECONDS ); scheduledExecutor.scheduleAtFixedRate( beaconsEvictionJob, scanDuration.scanDurationMillis, BEACON_EVICTION_PERIODICITY_MILLIS, TimeUnit.MILLISECONDS ); }
BeaconScanner implements IScanner { @Override public void start() { scheduledExecutor.schedule( scanResumeJob, 0L, TimeUnit.MILLISECONDS ); scheduledExecutor.scheduleAtFixedRate( beaconsEvictionJob, scanDuration.scanDurationMillis, BEACON_EVICTION_PERIODICITY_MILLIS, TimeUnit.MILLISECONDS ); } }
BeaconScanner implements IScanner { @Override public void start() { scheduledExecutor.schedule( scanResumeJob, 0L, TimeUnit.MILLISECONDS ); scheduledExecutor.scheduleAtFixedRate( beaconsEvictionJob, scanDuration.scanDurationMillis, BEACON_EVICTION_PERIODICITY_MILLIS, TimeUnit.MILLISECONDS ); } private  BeaconScanner(@NonNull IBleDevice bleDevice,
                          @NonNull ScanExecutorProvider scheduledExecutorProvider,
                          @NonNull IBeaconParser beaconParser,
                          @NonNull ITimeProvider timeProvider,
                          @NonNull ScanDuration scanDuration,
                          @Nullable Ranger ranger); }
BeaconScanner implements IScanner { @Override public void start() { scheduledExecutor.schedule( scanResumeJob, 0L, TimeUnit.MILLISECONDS ); scheduledExecutor.scheduleAtFixedRate( beaconsEvictionJob, scanDuration.scanDurationMillis, BEACON_EVICTION_PERIODICITY_MILLIS, TimeUnit.MILLISECONDS ); } private  BeaconScanner(@NonNull IBleDevice bleDevice,
                          @NonNull ScanExecutorProvider scheduledExecutorProvider,
                          @NonNull IBeaconParser beaconParser,
                          @NonNull ITimeProvider timeProvider,
                          @NonNull ScanDuration scanDuration,
                          @Nullable Ranger ranger); @Override void start(); @Override void stop(); @Nullable @Override Ranger getRanger(); }
BeaconScanner implements IScanner { @Override public void start() { scheduledExecutor.schedule( scanResumeJob, 0L, TimeUnit.MILLISECONDS ); scheduledExecutor.scheduleAtFixedRate( beaconsEvictionJob, scanDuration.scanDurationMillis, BEACON_EVICTION_PERIODICITY_MILLIS, TimeUnit.MILLISECONDS ); } private  BeaconScanner(@NonNull IBleDevice bleDevice,
                          @NonNull ScanExecutorProvider scheduledExecutorProvider,
                          @NonNull IBeaconParser beaconParser,
                          @NonNull ITimeProvider timeProvider,
                          @NonNull ScanDuration scanDuration,
                          @Nullable Ranger ranger); @Override void start(); @Override void stop(); @Nullable @Override Ranger getRanger();  }