public Optional<UserDto> authenticate(HttpRequest request) {
    return extractCredentialsFromHeader(request)
      .flatMap(credentials -> Optional.ofNullable(authenticate(credentials, request)));
  }
@Test
  public void authenticate_from_user_token() {
    UserDto user = db.users().insertUser();
    when(userTokenAuthentication.authenticate(request)).thenReturn(Optional.of(new UserAuthResult(user, new UserTokenDto().setName("my-token"), UserAuthResult.AuthType.TOKEN)));
    when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn("Basic " + toBase64("token:"));

    Optional<UserDto> userAuthenticated = underTest.authenticate(request);

    assertThat(userAuthenticated).isPresent();
    assertThat(userAuthenticated.get().getLogin()).isEqualTo(user.getLogin());
  }