### Question:
DefaultEndpointThenInvalidateRegion implements Function<Object, URI> { @Override public URI apply(@Nullable Object from) { try { return delegate.apply(from); } finally { bucketToRegionCache.invalidate(from.toString()); } } @Inject  DefaultEndpointThenInvalidateRegion(AssignCorrectHostnameForBucket delegate,
         @Bucket LoadingCache<String, Optional<String>> bucketToRegionCache); @Override URI apply(@Nullable Object from);  }### Answer:
@SuppressWarnings("unchecked") @Test public void testInvalidate() throws Exception { LoadingCache<String, Optional<String>> bucketToRegionCache = createMock(LoadingCache.class); bucketToRegionCache.invalidate("mybucket"); replay(bucketToRegionCache); AssignCorrectHostnameForBucket delegate = new AssignCorrectHostnameForBucket(REGION_TO_ENDPOINT, Functions.forMap(ImmutableMap.of("mybucket", Optional.of("us-west-1")))); new DefaultEndpointThenInvalidateRegion(delegate, bucketToRegionCache).apply("mybucket"); verify(bucketToRegionCache); }