class PathExtractor {

  String path(RequestContext context) {
    HttpServletRequest request = context.getRequest();
    StringBuilder builder = new StringBuilder();

    builder.append(request.getContextPath()).append(request.getServletPath());
    if (request.getPathInfo() != null) {
      builder.append(request.getPathInfo());
    }

    if (context.getRequestQueryParams() != null) {
      appendQueryParams(context, builder);
    }

    return builder.toString();
  }

}

class PathExtractorTest {

  private final RequestContext requestContext;
  private final HttpServletRequest servletRequest;
  private final Map<String, List<String>> queryParams;
  private final PathExtractor extractor;

  @Test
  public void extractsPathWithQueryStringAndPathInfo() {

    when(servletRequest.getPathInfo()).thenReturn("/id");
    when(requestContext.getRequestQueryParams()).thenReturn(queryParams);

    String path = extractor.path(requestContext);

    assertThat(path).isEqualTo("/root/path/to/resource/id?n=3&n=5");
  }

}