### Question:
PercentEncoder { public String encode(String str) { try { String urlEncoded = URLEncoder.encode(str, StandardCharsets.UTF_8.name()); return urlEncoded.replace("+", "%20"); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException("Shall not happen", ex); } }  String encode(String str); String decode(String str);  }### Answer:
@Test public void testEncode() { Assert.assertEquals("query%3Dworld%20nomads%26count%3D5", penc.encode("query=world nomads&count=5")); Assert.assertEquals("query%3DHe%20is%20%22Joe%22", penc.encode("query=He is \"Joe\"")); Assert.assertEquals("pattern%3Da%7Cb", penc.encode("pattern=a|b")); }