@Override public Image load(final RegionAndName key) throws Exception { // raw lookup of an image Supplier<Image> rawSupplier = new Supplier<Image>() { @Override public Image get() { try { return delegate.load(key); } catch (ExecutionException e) { throw Throwables.propagate(e); } } }; return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get(); }
@Override public Image load(final RegionAndName key) throws Exception { // raw lookup of an image Supplier<Image> rawSupplier = new Supplier<Image>() { @Override public Image get() { try { return delegate.load(key); } catch (ExecutionException e) { throw Throwables.propagate(e); } } }; return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get(); }
@Override public Image load(final RegionAndName key) throws Exception { // raw lookup of an image Supplier<Image> rawSupplier = new Supplier<Image>() { @Override public Image get() { try { return delegate.load(key); } catch (ExecutionException e) { throw Throwables.propagate(e); } } }; return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get(); }
@Override public Image load(final RegionAndName key) throws Exception { // raw lookup of an image Supplier<Image> rawSupplier = new Supplier<Image>() { @Override public Image get() { try { return delegate.load(key); } catch (ExecutionException e) { throw Throwables.propagate(e); } } }; return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get(); }
@Override public Image load(final RegionAndName key) throws Exception { // raw lookup of an image Supplier<Image> rawSupplier = new Supplier<Image>() { @Override public Image get() { try { return delegate.load(key); } catch (ExecutionException e) { throw Throwables.propagate(e); } } }; return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get(); }
@Override public Image load(final RegionAndName key) throws Exception { // raw lookup of an image Supplier<Image> rawSupplier = new Supplier<Image>() { @Override public Image get() { try { return delegate.load(key); } catch (ExecutionException e) { throw Throwables.propagate(e); } } }; return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get(); }
@Override public Image load(final RegionAndName key) throws Exception { // raw lookup of an image Supplier<Image> rawSupplier = new Supplier<Image>() { @Override public Image get() { try { return delegate.load(key); } catch (ExecutionException e) { throw Throwables.propagate(e); } } }; return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get(); }
@Override public Image load(final RegionAndName key) throws Exception { // raw lookup of an image Supplier<Image> rawSupplier = new Supplier<Image>() { @Override public Image get() { try { return delegate.load(key); } catch (ExecutionException e) { throw Throwables.propagate(e); } } }; return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get(); }
@Test public void testNormal() { AtomicReference<AuthorizationException> authException = Atomics.newReference(); assertEquals( new SetAndThrowAuthorizationExceptionSupplier<String>(Suppliers.ofInstance("foo"), authException).get(), "foo"); assertEquals(authException.get(), null); }
@Test public void testNormal() { AtomicReference<AuthorizationException> authException = Atomics.newReference(); assertEquals( new SetAndThrowAuthorizationExceptionSupplier<String>(Suppliers.ofInstance("foo"), authException).get(), "foo"); assertEquals(authException.get(), null); }
@Test(expectedExceptions = RuntimeException.class) public void testThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() { AtomicReference<AuthorizationException> authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier<String>(new Supplier<String>() { @Override public String get() { throw new RuntimeException(new IllegalArgumentException("foo")); } }, authException).get(); } finally { assertEquals(authException.get().getClass(), RuntimeException.class); } }
@Test(expectedExceptions = AuthorizationException.class) public void testThrowsAuthorizationExceptionAndAlsoSetsExceptionType() { AtomicReference<AuthorizationException> authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier<String>(new Supplier<String>() { @Override public String get() { throw new AuthorizationException(); } }, authException).get(); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = AuthorizationException.class) public void testThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenNested() { AtomicReference<AuthorizationException> authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier<String>(new Supplier<String>() { @Override public String get() { throw new RuntimeException(new ExecutionException(new AuthorizationException())); } }, authException).get(); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = AuthorizationException.class) public void testThrowsAuthorizationExceptionAndAlsoSetsExceptionType() { AtomicReference<AuthorizationException> authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier<String>(new Supplier<String>() { @Override public String get() { throw new AuthorizationException(); } }, authException).get(); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = AuthorizationException.class) public void testThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenNested() { AtomicReference<AuthorizationException> authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier<String>(new Supplier<String>() { @Override public String get() { throw new RuntimeException(new ExecutionException(new AuthorizationException())); } }, authException).get(); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = RuntimeException.class) public void testThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() { AtomicReference<AuthorizationException> authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier<String>(new Supplier<String>() { @Override public String get() { throw new RuntimeException(new IllegalArgumentException("foo")); } }, authException).get(); } finally { assertEquals(authException.get().getClass(), RuntimeException.class); } }