public static String appendQueryParams(HttpServletRequest request,
      String targetUri) {
    String ret = targetUri;
    String urlEncodedQueryString = getURLEncodedQueryString(request, null);
    if (urlEncodedQueryString != null) {
      ret += "?" + urlEncodedQueryString;
    }
    return ret;
  }
@Test
  void testAppendQueryParams() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    String targetUri = "/test/path";
    Mockito.when(request.getCharacterEncoding()).thenReturn(null);
    Map<String, String> paramResultMap = new HashMap<>();
    paramResultMap.put("param1=x", targetUri + "?" + "param1=x");
    paramResultMap
        .put("param1=x&param2=y", targetUri + "?" + "param1=x&param2=y");
    paramResultMap.put("param1=x&param2=y&param3=x+y",
        targetUri + "?" + "param1=x&param2=y&param3=x+y");

    for (Map.Entry<String, String> entry : paramResultMap.entrySet()) {
      Mockito.when(request.getQueryString()).thenReturn(entry.getKey());
      String uri = WebAppUtils.appendQueryParams(request, targetUri);
      assertEquals(entry.getValue(), uri);
    }
  }