@Test
  public void testOnAuthFailure() throws Exception {
    final ExecutionContextProvider ecProvider = Mockito.mock(ExecutionContextProvider.class);
    Mockito.when(ecProvider.get()).thenReturn(new DefaultDeadboltExecutionContextProvider());
    DeadboltHandler deadboltHandler =
        new AbstractDeadboltHandler(ecProvider) {
          @Override
          public CompletionStage<Optional<Result>> beforeAuthCheck(final Http.Context context) {
            return CompletableFuture.completedFuture(Optional.empty());
          }
        };

    final Http.Context context = Mockito.mock(Http.Context.class);

    final CompletionStage<Result> promise =
        deadboltHandler.onAuthFailure(context, Optional.of("foo"));
    Assert.assertNotNull(promise);

    final Result result = promise.toCompletableFuture().get(100, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    Assert.assertEquals(401, result.status());
  }
  @Test
  public void testGetDynamicResourceHandler() throws Exception {
    final ExecutionContextProvider ecProvider = Mockito.mock(ExecutionContextProvider.class);
    Mockito.when(ecProvider.get()).thenReturn(new DefaultDeadboltExecutionContextProvider());
    DeadboltHandler deadboltHandler =
        new AbstractDeadboltHandler(ecProvider) {
          @Override
          public CompletionStage<Optional<Result>> beforeAuthCheck(final Http.Context context) {
            return CompletableFuture.completedFuture(Optional.empty());
          }
        };

    final Http.Context context = Mockito.mock(Http.Context.class);

    final CompletionStage<Optional<DynamicResourceHandler>> promise =
        deadboltHandler.getDynamicResourceHandler(context);
    Assert.assertNotNull(promise);

    final Optional<DynamicResourceHandler> option =
        promise.toCompletableFuture().get(1000, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(option);
    Assert.assertFalse(option.isPresent());
  }