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

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