title: How to mock requestContext.getUriInfo().getPathParameters() from Jersey in java
body: <p>I have written one jersey request filter and I want to unit test this. Below is the code.</p>
  
  <pre><code>@Override
  public void filter(ContainerRequestContext containerRequestContext) throws IOException {
      logPathParameters(containerRequestContext);
  }
  private void logPathParameters(ContainerRequestContext requestContext) {
      StringBuilder parameterStringBuilder = new StringBuilder();
      MultivaluedMap&lt;String, String&gt; pathParameters = requestContext.getUriInfo().getPathParameters();   
      if(!pathParameters.isEmpty()) {
          Iterator iterator = pathParameters.keySet().iterator();
          while (iterator.hasNext()) {
              String name = iterator.next().toString();
              String paramValue = pathParameters.getFirst(name);
              String shortParamName = getShortNameForPathParameter(name);
              parameterStringBuilder.append(String.format("paramName: %s, paramValue: %s; ", shortParamName, paramValue));
          }
          if (parameterStringBuilder.length() &gt; 0) {
              MDC.put("pathParam ", parameterStringBuilder.toString());
              System.out.println(parameterStringBuilder.toString());
          }
      }
  }
  </code></pre>
  
  <p>To unit test above filter function I have to mock ContainerRequestContext. So I created below function. </p>
  
  <pre><code>private ContainerRequestContext mockContainerRequest(String uri)
    throws URISyntaxException
    {
      ContainerRequestContext requestContext = mock(ContainerRequestContext.class);
      UriInfo uriInfo = mock(UriInfo.class);
      URI requestUri = new URI(uri);
      when(uriInfo.getRequestUri()).thenReturn(requestUri);
      when(requestContext.getUriInfo()).thenReturn(uriInfo);
      return requestContext;
  }
  </code></pre>
  
  <p>Here I want to mock getPathParameters of uriInfo, this will return path parameter present in the input uri string to this function.
  Is there any utility function which can do this for me. Like if I pass url to it, it should return me the MultivaluedMap of path Parameters.</p>
  
  <p>Something similar mentioned in the answer of below question. </p>
  
  <p><a href="https://stackoverflow.com/questions/34096241/mocking-uriinfo-using-mockito-and-the-response-is-not-as-expected">example</a></p>
  
  <p>This is done for query parameters. I want to do it for path Parameters. I don't want to build it manually. Some kind of utility function should be good. </p>