DefaultEndpointThenInvalidateRegion implements Function<Object, URI> { @Override public URI apply(@Nullable Object from) { try { return r2.apply(from); } finally { bucketToRegionCache.invalidate(from.toString()); } } @Inject  DefaultEndpointThenInvalidateRegion(AssignCorrectHostnameForBucket r2,
            @Bucket LoadingCache<String, Optional<String>> bucketToRegionCache); @Override URI apply(@Nullable Object from);  }
@SuppressWarnings("unchecked") @Test void testInvalidate() throws Exception { AssignCorrectHostnameForBucket r2 = createMock(AssignCorrectHostnameForBucket.class); LoadingCache<String, Optional<String>> bucketToRegionCache = createMock(LoadingCache.class); expect(r2.apply("mybucket")).andReturn(URI.create("http: bucketToRegionCache.invalidate("mybucket"); replay(r2, bucketToRegionCache); new DefaultEndpointThenInvalidateRegion(r2, bucketToRegionCache).apply("mybucket"); verify(r2, bucketToRegionCache); }