### Question:
Param { public static String toSortedString(final String separator, final Param<?, ?>... parameters) { Arrays.sort(parameters, NAME_CMP); final StringBuilder b = new StringBuilder(); try { for(Param<?, ?> p : parameters) { if (p.getValue() != null) { b.append(separator).append( URLEncoder.encode(p.getName(), "UTF-8") + "=" + URLEncoder.encode(p.getValueString(), "UTF-8")); } } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return b.toString(); } Param(final D domain, final T value); static String toSortedString(final String separator,
      final Param<?, ?>... parameters); final T getValue(); abstract String getValueString(); abstract String getName(); @Override String toString();  }### Answer:
@Test public void testToSortedStringEscapesURICharacters() { final String sep = "&"; Param<?, ?> ampParam = new TokenArgumentParam("token&ampersand"); Param<?, ?> equalParam = new RenewerParam("renewer=equal"); final String expected = "&renewer=renewer%3Dequal&token=token%26ampersand"; final String actual = Param.toSortedString(sep, equalParam, ampParam); Assert.assertEquals(expected, actual); }