@Test
public void testExtractHeaderToken() {

    String tokenString = null;
    Enumeration<String> headers = null;
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    // strict bearer token
    headers = Collections.enumeration(Arrays.asList("Bearer dummy_access_token_1"));
    Mockito.when(request.getHeaders("Authorization")).thenReturn(headers);
    tokenString = OAuthAuthorityUtils.extractHeaderToken(request);
    assertEquals(tokenString, "dummy_access_token_1");
    // case-insensitive bearer token
    headers = Collections.enumeration(Arrays.asList("bearer dummy_access_token_2"));
    Mockito.when(request.getHeaders("Authorization")).thenReturn(headers);
    tokenString = OAuthAuthorityUtils.extractHeaderToken(request);
    assertEquals(tokenString, "dummy_access_token_2");
    // multiple bearer token
    headers = Collections.enumeration(Arrays.asList("Bearer dummy_access_token_3,dummy_access_token_4"));
    Mockito.when(request.getHeaders("Authorization")).thenReturn(headers);
    tokenString = OAuthAuthorityUtils.extractHeaderToken(request);
    assertEquals(tokenString, "dummy_access_token_3");
    // empty header
    Mockito.when(request.getHeaders("Authorization")).thenReturn(Collections.emptyEnumeration());
    tokenString = OAuthAuthorityUtils.extractHeaderToken(request);
    assertEquals(tokenString, null);
    // non-bearer header
    headers = Collections.enumeration(Arrays.asList("Basic encoded_password"));
    Mockito.when(request.getHeaders("Authorization")).thenReturn(headers);
    tokenString = OAuthAuthorityUtils.extractHeaderToken(request);
    assertEquals(tokenString, null);
}