ExecutorWrappers { public static TokenInfoRequestExecutor wrap(TokenInfoRequestExecutor tokenInfoRequestExecutor) { return new RequestExecutorWrapper(tokenInfoRequestExecutor, rethrowExceptionsAsList(OAuth2Exception.class), new InvalidTokenException(ACCESS_TOKEN_NOT_VALID)); }  static TokenInfoRequestExecutor wrap(TokenInfoRequestExecutor tokenInfoRequestExecutor); static TokenInfoRequestExecutor wrap(TokenInfoRequestExecutor tokenInfoRequestExecutor,
            OAuth2Exception cause); static TokenInfoRequestExecutor wrap(TokenInfoRequestExecutor tokenInfoRequestExecutor,
            List<Class<? extends RuntimeException>> rethrowExceptions); static TokenInfoRequestExecutor wrap(TokenInfoRequestExecutor tokenInfoRequestExecutor,
            List<Class<? extends RuntimeException>> rethrowExceptions, OAuth2Exception cause); static List<Class<? extends RuntimeException>> rethrowExceptionsAsList(
            Class<? extends RuntimeException>... classes);  }
@Test public void testDefaultWithCustomOAuth2Exception() { TokenInfoRequestExecutor wrapped = ExecutorWrappers.wrap(executor, new UnsupportedResponseTypeException("TEST_CAUSE")); Mockito.when(executor.getMap(Mockito.eq(TOKEN))).thenThrow(new RuntimeException("TEST_RUNTIME_EXCEPTION")); try { wrapped.getMap(TOKEN); Assertions.fail("Should throw an exception"); } catch (InvalidTokenException e) { Assertions.fail("InvalidTokenException expected"); } catch (OAuth2Exception e) { Assertions.assertThat(e.getMessage()).isEqualTo("TEST_CAUSE"); } catch (RuntimeException e) { Assertions.fail("InvalidTokenException expected"); } }
@Test public void testDefaultWithSuccessfullExecution() { TokenInfoRequestExecutor wrapped = ExecutorWrappers.wrap(executor, new UnsupportedResponseTypeException("TEST_CAUSE")); Mockito.when(executor.getMap(Mockito.eq(TOKEN))).thenReturn(new HashMap<String, Object>()); wrapped.getMap(TOKEN); }
@Test public void testDefault() { TokenInfoRequestExecutor wrapped = ExecutorWrappers.wrap(executor); Mockito.when(executor.getMap(Mockito.eq(TOKEN))).thenThrow(new RuntimeException("TEST_RUNTIME_EXCEPTION")); try { wrapped.getMap(TOKEN); Assertions.fail("Should throw an exception"); } catch (InvalidTokenException e) { } catch (RuntimeException e) { Assertions.fail("InvalidTokenException expected"); } }
@Test public void testDefaultWithOAuth2Exception() { TokenInfoRequestExecutor wrapped = ExecutorWrappers.wrap(executor); Mockito.when(executor.getMap(Mockito.eq(TOKEN))).thenThrow(new OAuth2Exception("TEST_RUNTIME_EXCEPTION")); try { wrapped.getMap(TOKEN); Assertions.fail("Should throw an exception"); } catch (InvalidTokenException e) { Assertions.fail("InvalidTokenException expected"); } catch (OAuth2Exception e) { } catch (RuntimeException e) { Assertions.fail("InvalidTokenException expected"); } }