/** * Execute {@link Cache#get(Object)} on the specified {@link Cache} and * invoke the error handler if an exception occurs. Return {@code null} * if the handler does not throw any exception, which simulates a cache * miss in case of error. * @see Cache#get(Object) */ @Nullable protected Cache.ValueWrapper doGet(Cache cache, Object key) { try { return cache.get(key); } catch (RuntimeException ex) { getErrorHandler().handleCacheGetError(ex, cache, key); return null; // If the exception is handled, return a cache miss } }
/** * Execute {@link Cache#get(Object)} on the specified {@link Cache} and * invoke the error handler if an exception occurs. Return {@code null} * if the handler does not throw any exception, which simulates a cache * miss in case of error. * @see Cache#get(Object) */ @Nullable protected Cache.ValueWrapper doGet(Cache cache, Object key) { try { return cache.get(key); } catch (RuntimeException ex) { getErrorHandler().handleCacheGetError(ex, cache, key); return null; // If the exception is handled, return a cache miss } }
@Test public void getFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).get(key); this.simpleService.get(0L); verify(this.errorHandler).handleCacheGetError(exception, this.cache, key); }
@Test public void getFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get"); willThrow(exception).given(this.cache).get(0L); Object result = this.simpleService.get(0L); verify(this.errorHandler).handleCacheGetError(exception, cache, 0L); verify(this.cache).get(0L); verify(this.cache).put(0L, result); // result of the invocation }
/** * Execute {@link Cache#get(Object)} on the specified {@link Cache} and * invoke the error handler if an exception occurs. Return {@code null} * if the handler does not throw any exception, which simulates a cache * miss in case of error. * @see Cache#get(Object) */ @Nullable protected Cache.ValueWrapper doGet(Cache cache, Object key) { try { return cache.get(key); } catch (RuntimeException ex) { getErrorHandler().handleCacheGetError(ex, cache, key); return null; // If the exception is handled, return a cache miss } }