@Test public void testLoaderNormal() { AtomicReference<AuthorizationException> authException = newReference(); assertEquals(new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(ofInstance("foo"), authException).load("KEY").get(), "foo"); assertEquals(authException.get(), null); }
@Test(expectedExceptions = AuthorizationException.class) public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenNested() { AtomicReference<AuthorizationException> authException = newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() { public String get() { throw new RuntimeException(new ExecutionException(new AuthorizationException())); } }, authException).load("KEY"); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = AuthorizationException.class) public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenInUncheckedExecutionException() { AtomicReference<AuthorizationException> authException = newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() { public String get() { throw new UncheckedExecutionException(new AuthorizationException()); } }, authException).load("KEY"); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = RuntimeException.class) public void testLoaderThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() { AtomicReference<AuthorizationException> authException = newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() { public String get() { throw new RuntimeException(new IllegalArgumentException("foo")); } }, authException, new ValueLoadedCallback.NoOpCallback<String>()).load("KEY"); } finally { assertEquals(authException.get().getClass(), RuntimeException.class); } }
@Test(expectedExceptions = AuthorizationException.class) public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenInUncheckedExecutionException() { AtomicReference<AuthorizationException> authException = newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() { public String get() { throw new UncheckedExecutionException(new AuthorizationException()); } }, authException, new ValueLoadedCallback.NoOpCallback<String>()).load("KEY"); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = AuthorizationException.class) public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionType() { AtomicReference<AuthorizationException> authException = newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() { public String get() { throw new AuthorizationException(); } }, authException, new ValueLoadedCallback.NoOpCallback<String>()).load("KEY"); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = AuthorizationException.class) public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenNested() { AtomicReference<AuthorizationException> authException = newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() { public String get() { throw new RuntimeException(new ExecutionException(new AuthorizationException())); } }, authException, new ValueLoadedCallback.NoOpCallback<String>()).load("KEY"); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test(expectedExceptions = RuntimeException.class) public void testLoaderThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() { AtomicReference<AuthorizationException> authException = newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() { public String get() { throw new RuntimeException(new IllegalArgumentException("foo")); } }, authException).load("KEY"); } finally { assertEquals(authException.get().getClass(), RuntimeException.class); } } }
@Test(expectedExceptions = AuthorizationException.class) public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionType() { AtomicReference<AuthorizationException> authException = newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(new Supplier<String>() { public String get() { throw new AuthorizationException(); } }, authException).load("KEY"); } finally { assertEquals(authException.get().getClass(), AuthorizationException.class); } }
@Test public void testLoaderNormal() { AtomicReference<AuthorizationException> authException = newReference(); assertEquals(new SetAndThrowAuthorizationExceptionSupplierBackedLoader<String>(ofInstance("foo"), authException, new ValueLoadedCallback.NoOpCallback<String>()).load("KEY").get(), "foo"); assertEquals(authException.get(), null); }