AnalyticsCacheSettings { public long progressiveExpirationTimeOrDefault( final Date dateBeforeToday ) { return new TimeToLive( dateBeforeToday, getProgressiveTtlFactorOrDefault() ).compute(); } AnalyticsCacheSettings( final SystemSettingManager systemSettingManager ); boolean isProgressiveCachingEnabled(); boolean isFixedCachingEnabled(); long progressiveExpirationTimeOrDefault( final Date dateBeforeToday ); long fixedExpirationTimeOrDefault(); boolean isCachingEnabled();  }
@Test public void testProgressiveExpirationTimeOrDefaultWhenTheTtlFactorIsSet() { final int aTtlFactor = 20; final int oneDayDiff = 1; final long theExpectedTtl = aTtlFactor * oneDayDiff; final Date aDateBeforeToday = calculateDateFrom( new Date(), minus( oneDayDiff ), DATE ); when( systemSettingManager.getSystemSetting( ANALYTICS_CACHE_PROGRESSIVE_TTL_FACTOR ) ) .thenReturn( aTtlFactor ); final long expirationTime = analyticsCacheSettings.progressiveExpirationTimeOrDefault( aDateBeforeToday ); assertThat( expirationTime, is( theExpectedTtl ) ); }
@Test public void testProgressiveExpirationTimeOrDefaultWhenTheTtlFactorIsNotSet() { final int theDefaultTtlFactor = (Integer) ANALYTICS_CACHE_PROGRESSIVE_TTL_FACTOR.getDefaultValue(); final int oneDayDiff = 1; final long theExpectedTtl = theDefaultTtlFactor * oneDayDiff; final Date aDateBeforeToday = calculateDateFrom( new Date(), minus( oneDayDiff ), DATE ); when( systemSettingManager.getSystemSetting( ANALYTICS_CACHE_PROGRESSIVE_TTL_FACTOR ) ) .thenReturn( theDefaultTtlFactor ); final long expirationTime = analyticsCacheSettings.progressiveExpirationTimeOrDefault( aDateBeforeToday ); assertThat( expirationTime, is( theExpectedTtl ) ); }
@Test public void testProgressiveExpirationTimeOrDefaultWhenTheTtlFactorIsSetWithNegativeNumber() { final int aTtlFactor = -20; final int oneDayDiff = 1; final int theExpectedTtlFactor = 1; final Date aDateBeforeToday = calculateDateFrom( new Date(), minus( oneDayDiff ), DATE ); when( systemSettingManager.getSystemSetting( ANALYTICS_CACHE_PROGRESSIVE_TTL_FACTOR ) ) .thenReturn( aTtlFactor ); final long expirationTime = analyticsCacheSettings.progressiveExpirationTimeOrDefault( aDateBeforeToday ); assertThat( expirationTime, is( valueOf( theExpectedTtlFactor ) ) ); }