### Question:
RememberTheMilkSignatureGenerator { public URL getSignature(String base, Map<String, String> queryParams) { Map<String, String> modifiedParams = new HashMap<>(); modifiedParams.putAll(queryParams); modifiedParams.put("api_key", appCredentials.getKey()); modifiedParams.put("auth_token", authToken); List<String> orderedKeys = modifiedParams.keySet().stream().collect(Collectors.toList()); Collections.sort(orderedKeys); List<String> queryParamStrings = new ArrayList<>(); StringBuilder resultBuilder = new StringBuilder(); resultBuilder.append(appCredentials.getSecret()); for (String key : orderedKeys) { String k = key.trim(); String v = modifiedParams.get(key).trim(); resultBuilder.append(k).append(v); queryParamStrings.add(k + "=" + v); } try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] thedigest = md.digest(resultBuilder.toString().getBytes(StandardCharsets.UTF_8)); String signature = BaseEncoding.base16().encode(thedigest).toLowerCase(); return new URL(base + "?" + String.join("&", queryParamStrings) + "&api_sig=" + signature); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("Couldn't find MD5 hash", e); } catch (MalformedURLException e) { throw new IllegalArgumentException("Couldn't parse authUrl", e); } } RememberTheMilkSignatureGenerator(AppCredentials appCredentials, String authToken); URL getSignature(String base, Map<String, String> queryParams);  }### Answer:
@Test public void signatureTest() throws Exception { String base = "http: Map<String, String> queryParams = ImmutableMap.of("yxz", "foo", "feg", "bar", "abc", "baz"); URL expected = new URL( base + "?abc=baz&api_key=BANANAS1&auth_token=BANANAS3&feg=bar&yxz=foo&api_sig=b48f0dd1a18179b3068b16728e214561"); assertThat(SIGNATURE_GENERATOR.getSignature(base, queryParams)).isEqualTo(expected); }
@Test public void signatureTestWhiteSpace() throws Exception{ String base = "http: Map<String, String> queryParams = ImmutableMap.of("abc", "baz", "foo", "b a r "); URL expected = new URL(base + "?abc=baz&api_key=BANANAS1&auth_token=BANANAS3&foo=b a r&api_sig=204b1dc1abbff7a5e8753d7102d966f4"); assertThat(SIGNATURE_GENERATOR.getSignature(base, queryParams)).isEqualTo(expected); }