S3TogglzRepository implements StateRepository { @Override public FeatureState getFeatureState(final Feature feature) { final CacheEntry cachedEntry = cache.get(feature.name()); if (cachedEntry != null) { return cachedEntry.getState(); } final FeatureState featureState = featureStateConverter.retrieveFeatureStateFromS3(feature); cache.put(feature.name(), new CacheEntry(featureState)); return featureState; } S3TogglzRepository(final FeatureStateConverter featureStateConverter); @Override FeatureState getFeatureState(final Feature feature); @Override void setFeatureState(final FeatureState featureState);  }
@Test public void shouldFetchInitialTogglzStatefromDelegateAndServeSubsequentRequestsFromCache() { when(featureStateConverter.retrieveFeatureStateFromS3(feature)).thenReturn(featureState); s3TogglzRepository.getFeatureState(feature); s3TogglzRepository.getFeatureState(feature); s3TogglzRepository.getFeatureState(feature); verify(featureStateConverter, times(1)).retrieveFeatureStateFromS3(feature); }