### Question:
UriUtil { @NonNull public static String formUrlEncode(@Nullable Map<String, String> parameters) { if (parameters == null) { return ""; } List<String> queryParts = new ArrayList<>(); for (Map.Entry<String, String> param : parameters.entrySet()) { queryParts.add(param.getKey() + "=" + formUrlEncodeValue(param.getValue())); } return TextUtils.join("&", queryParts); } private  UriUtil(); static Uri parseUriIfAvailable(@Nullable String uri); static void appendQueryParameterIfNotNull(
            @NonNull Uri.Builder uriBuilder,
            @NonNull String paramName,
            @Nullable Object value); static Long getLongQueryParameter(@NonNull Uri uri, @NonNull String param); static List<Bundle> toCustomTabUriBundle(Uri[] uris, int startIndex); @NonNull static String formUrlEncode(@Nullable Map<String, String> parameters); @NonNull static String formUrlEncodeValue(@NonNull String value); static List<Pair<String, String>> formUrlDecode(String encoded); static Map<String, String> formUrlDecodeUnique(String encoded);  }### Answer:
@Test public void testFormUrlEncode() { Map<String, String> parameters = new HashMap<>(); parameters.put("test1", "value1"); parameters.put("test2", "value2"); String query = UriUtil.formUrlEncode(parameters); mSanitizer.parseQuery(query); for (Map.Entry<String, String> param : parameters.entrySet()) { assertThat(mSanitizer.getValue(param.getKey())).isEqualTo(param.getValue()); } }
@Test public void testFormUrlEncode_withSpaceSeparatedValueForParameter() { Map<String, String> parameters = new HashMap<>(); parameters.put("test1", "value1"); parameters.put("test2", "value2 value3"); String query = UriUtil.formUrlEncode(parameters); assertThat(query.contains("value2+value3")); mSanitizer.parseQuery(query); for (Map.Entry<String, String> param : parameters.entrySet()) { assertThat(mSanitizer.getValue(param.getKey())).isEqualTo(param.getValue()); } }
@Test public void testFormUrlEncode_withNull() { assertThat(UriUtil.formUrlEncode(null)).isEqualTo(""); }
@Test public void testFormUrlEncode_withEmpty() { assertThat(UriUtil.formUrlEncode(new HashMap<String, String>())).isEqualTo(""); }