@Test public void shouldRefreshKey_whenKeyExpiryIsInThePast_returnsTrue() { Calendar fixedCalendar = Calendar.getInstance(); EphemeralKey key = EphemeralKey.fromString(FIRST_SAMPLE_KEY_RAW); assertNotNull(key); long currentTimeInMillis = fixedCalendar.getTimeInMillis(); long timeAgoInMillis = currentTimeInMillis - 100L; key.setExpires(TimeUnit.MILLISECONDS.toSeconds(timeAgoInMillis)); assertTrue(EphemeralKeyManager.shouldRefreshKey(key, TEST_SECONDS_BUFFER, fixedCalendar)); }
static boolean shouldRefreshKey( @Nullable EphemeralKey key, long bufferInSeconds, @Nullable Calendar proxyCalendar) { if (key == null) { return true; } Calendar now = proxyCalendar == null ? Calendar.getInstance() : proxyCalendar; long nowInSeconds = TimeUnit.MILLISECONDS.toSeconds(now.getTimeInMillis()); long nowPlusBuffer = nowInSeconds + bufferInSeconds; return key.getExpires() < nowPlusBuffer; }
EphemeralKeyManager { static boolean shouldRefreshKey( @Nullable EphemeralKey key, long bufferInSeconds, @Nullable Calendar proxyCalendar) { if (key == null) { return true; } Calendar now = proxyCalendar == null ? Calendar.getInstance() : proxyCalendar; long nowInSeconds = TimeUnit.MILLISECONDS.toSeconds(now.getTimeInMillis()); long nowPlusBuffer = nowInSeconds + bufferInSeconds; return key.getExpires() < nowPlusBuffer; } }
EphemeralKeyManager { static boolean shouldRefreshKey( @Nullable EphemeralKey key, long bufferInSeconds, @Nullable Calendar proxyCalendar) { if (key == null) { return true; } Calendar now = proxyCalendar == null ? Calendar.getInstance() : proxyCalendar; long nowInSeconds = TimeUnit.MILLISECONDS.toSeconds(now.getTimeInMillis()); long nowPlusBuffer = nowInSeconds + bufferInSeconds; return key.getExpires() < nowPlusBuffer; } EphemeralKeyManager(
            @NonNull EphemeralKeyProvider ephemeralKeyProvider,
            @NonNull KeyManagerListener keyManagerListener,
            long timeBufferInSeconds,
            @Nullable Calendar overrideCalendar); }
EphemeralKeyManager { static boolean shouldRefreshKey( @Nullable EphemeralKey key, long bufferInSeconds, @Nullable Calendar proxyCalendar) { if (key == null) { return true; } Calendar now = proxyCalendar == null ? Calendar.getInstance() : proxyCalendar; long nowInSeconds = TimeUnit.MILLISECONDS.toSeconds(now.getTimeInMillis()); long nowPlusBuffer = nowInSeconds + bufferInSeconds; return key.getExpires() < nowPlusBuffer; } EphemeralKeyManager(
            @NonNull EphemeralKeyProvider ephemeralKeyProvider,
            @NonNull KeyManagerListener keyManagerListener,
            long timeBufferInSeconds,
            @Nullable Calendar overrideCalendar);  }
EphemeralKeyManager { static boolean shouldRefreshKey( @Nullable EphemeralKey key, long bufferInSeconds, @Nullable Calendar proxyCalendar) { if (key == null) { return true; } Calendar now = proxyCalendar == null ? Calendar.getInstance() : proxyCalendar; long nowInSeconds = TimeUnit.MILLISECONDS.toSeconds(now.getTimeInMillis()); long nowPlusBuffer = nowInSeconds + bufferInSeconds; return key.getExpires() < nowPlusBuffer; } EphemeralKeyManager(
            @NonNull EphemeralKeyProvider ephemeralKeyProvider,
            @NonNull KeyManagerListener keyManagerListener,
            long timeBufferInSeconds,
            @Nullable Calendar overrideCalendar);   }