class AbstractBearerTokenExtractor {

    public String getBearerToken() {
        final String tokenHeaderName = authContextInfo.getTokenHeader();
        final boolean fallbackToHeader = authContextInfo.isAlwaysCheckAuthorization();
        AuthLogging.log.tokenHeaderName(tokenHeaderName);

        final String bearerValue;

        if (COOKIE_HEADER.equals(tokenHeaderName)) {
            String intermediateBearerValue = getBearerTokenCookie();
            if (intermediateBearerValue == null && fallbackToHeader) {
                bearerValue = getBearerTokenAuthHeader();
            } else {
                bearerValue = intermediateBearerValue;
            }
        } else if (AUTHORIZATION_HEADER.equals(tokenHeaderName)) {
            bearerValue = getBearerTokenAuthHeader();
        } else {
            String customHeaderValue = getHeaderValue(tokenHeaderName);

            if (customHeaderValue == null) {
                AuthLogging.log.headerIsNull(tokenHeaderName);
            } else {
                String customHeaderSchemeValue = getTokenWithConfiguredScheme(customHeaderValue);
                if (customHeaderSchemeValue != null) {
                    customHeaderValue = customHeaderSchemeValue;
                }
            }
            bearerValue = customHeaderValue;
        }

        return bearerValue;
    }

}

class AbstractBearerTokenExtractorTest {

    private static final String AUTHORIZATION;
    private static final String COOKIE;
    private static final List<String> BEARER_SCHEME;
    @Mock JWTAuthContextInfo authContextInfo;
     AbstractBearerTokenExtractor target;

    @Test
    public void testGetBearerTokenFallbackToHeaderWithCookieHeader() {

        when(authContextInfo.getTokenHeader()).thenReturn(COOKIE);
        when(authContextInfo.isAlwaysCheckAuthorization()).thenReturn(true);
        AbstractBearerTokenExtractor target = newTarget(h -> "Bearer THE_HEADER_TOKEN", c -> "THE_COOKIE_TOKEN");
        String bearerToken = target.getBearerToken();
        assertEquals("THE_COOKIE_TOKEN", bearerToken);
    }

}