HTTPRequestHelper { public static void urlEncoding(StringBuilder builder, Map<String, String> params) { boolean added = false; for (Map.Entry<String, String> entry : params.entrySet()) { String value = entry.getValue(); if (added) builder.append('&'); builder.append(encode(entry.getKey(), UTF_8)).append('='); if (value != null && !value.isEmpty()) builder.append(encode(value, UTF_8)); added = true; } }  static void urlEncoding(StringBuilder builder, Map<String, String> params);  }
@Test void encodeWithEmptyValue() { var builder = new StringBuilder(); Map<String, String> params = new LinkedHashMap<>(); params.put("key1", ""); params.put("key2", "value2"); params.put("key3", null); HTTPRequestHelper.urlEncoding(builder, params); assertThat(builder.toString()).isEqualTo("key1=&key2=value2&key3="); }
@Test void encode() { var builder = new StringBuilder(); Map<String, String> params = new LinkedHashMap<>(); params.put("key1", "value1"); params.put("key2", "value2"); HTTPRequestHelper.urlEncoding(builder, params); assertThat(builder.toString()).isEqualTo("key1=value1&key2=value2"); }