@Test public void testAddHeader() { TokenHandler tp = TokenHandler.forHeader("Authorization"); Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); headers.put("Authorization", singletonList("firstToken")); tp.addHeader(headers, "secondToken"); List<String> authorization = headers.get("Authorization"); assertThat(authorization.size(), is(2)); assertThat(authorization, is(List.of("firstToken", "secondToken"))); assertThat(tp.tokenHeader(), is("Authorization")); }
public void addHeader(Map<String, List<String>> headers, String token) { String tokenValue = headerCreator.apply(token); List<String> values = headers.get(tokenHeader); if (null == values) { values = singletonList(tokenValue); } else { values = new ArrayList<>(values); values.add(tokenValue); } headers.put(tokenHeader, values); }
TokenHandler { public void addHeader(Map<String, List<String>> headers, String token) { String tokenValue = headerCreator.apply(token); List<String> values = headers.get(tokenHeader); if (null == values) { values = singletonList(tokenValue); } else { values = new ArrayList<>(values); values.add(tokenValue); } headers.put(tokenHeader, values); } }
TokenHandler { public void addHeader(Map<String, List<String>> headers, String token) { String tokenValue = headerCreator.apply(token); List<String> values = headers.get(tokenHeader); if (null == values) { values = singletonList(tokenValue); } else { values = new ArrayList<>(values); values.add(tokenValue); } headers.put(tokenHeader, values); } private  TokenHandler(Builder builder); }
TokenHandler { public void addHeader(Map<String, List<String>> headers, String token) { String tokenValue = headerCreator.apply(token); List<String> values = headers.get(tokenHeader); if (null == values) { values = singletonList(tokenValue); } else { values = new ArrayList<>(values); values.add(tokenValue); } headers.put(tokenHeader, values); } private  TokenHandler(Builder builder); static Builder builder(); static TokenHandler forHeader(String header); static TokenHandler create(Config config); Optional<String> extractToken(Map<String, List<String>> headers); String extractToken(String tokenRawValue); String tokenHeader(); void header(Map<String, List<String>> headers, String token); void addHeader(Map<String, List<String>> headers, String token); }
TokenHandler { public void addHeader(Map<String, List<String>> headers, String token) { String tokenValue = headerCreator.apply(token); List<String> values = headers.get(tokenHeader); if (null == values) { values = singletonList(tokenValue); } else { values = new ArrayList<>(values); values.add(tokenValue); } headers.put(tokenHeader, values); } private  TokenHandler(Builder builder); static Builder builder(); static TokenHandler forHeader(String header); static TokenHandler create(Config config); Optional<String> extractToken(Map<String, List<String>> headers); String extractToken(String tokenRawValue); String tokenHeader(); void header(Map<String, List<String>> headers, String token); void addHeader(Map<String, List<String>> headers, String token);  }