### Question:
OAuthUtil { public String createAuthorization(HttpMethod method, String url, List<? extends Entry<String, String>> params) { Validate.notNull(method, "method must not be null"); Validate.notEmpty(url, "url must not be empty"); String baseUrl = UrlHelper.parseBaseUrl(url); if (!url.equals(baseUrl)) { throw new IllegalArgumentException(url + " is not a base URL (base = " + baseUrl + ")"); } List<Pair<String, String>> oAuthHeader = new ArrayList<>(); oAuthHeader.add(Pair.of("oauth_consumer_key", oAuthParams.getConsumerKey())); oAuthHeader.add(Pair.of("oauth_nonce", createRandomString())); oAuthHeader.add(Pair.of("oauth_signature_method", "HMAC-SHA1")); oAuthHeader.add(Pair.of("oauth_timestamp", createTimestamp())); if (oAuthParams.getAccessToken() != null) { oAuthHeader.add(Pair.of("oauth_token", oAuthParams.getAccessToken())); } oAuthHeader.add(Pair.of("oauth_version", "1.0")); List<Entry<String, String>> allParams = new ArrayList<>(); if (params != null) { allParams.addAll(params); } allParams.addAll(oAuthHeader); String sigBaseString = createSignatureBaseString(method, url, allParams); String sigKey = createSigningKey(oAuthParams.getConsumerSecret(), oAuthParams.getAccessTokenSecret()); oAuthHeader.add(Pair.of("oauth_signature", createSignature(sigBaseString, sigKey))); Collections.sort(oAuthHeader); StringBuilder authorization = new StringBuilder(); authorization.append("OAuth "); boolean first = true; for (Pair<String, String> pair : oAuthHeader) { if (first) { first = false; } else { authorization.append(", "); } authorization.append(String.format("%s=\"%s\"", urlEncode(pair.getKey()), urlEncode(pair.getValue()))); } return authorization.toString(); } OAuthUtil(OAuthParams params); HttpRequest2 createSignedRequest(HttpRequest2 httpRequest); String createAuthorization(HttpMethod method, String url, List<? extends Entry<String, String>> params); static final String AUTHORIZATION_HEADER_KEY; }### Answer:
@Test public void testCreateAuthorization() { String authorizationParam = OATH_UTIL_UNDER_TEST.createAuthorization(HTTP_METHOD, BASE_URL, null); assertEquals(EXPECTED_AUTHORIZATION_PARAM, authorizationParam); }