### Question:
PathInfoUtil { public static String getQueryParam(final SlingHttpServletRequest request, final String key) { return request.getParameter(key); } private  PathInfoUtil(); static String getQueryParam(final SlingHttpServletRequest request, final String key); static String getQueryParam(final SlingHttpServletRequest request, final String key, final String dfault); static String getSelector(final SlingHttpServletRequest request, final int index); static String getSelector(final SlingHttpServletRequest request,
                                     final int index, final String defaultValue); static String[] getSuffixSegments(final SlingHttpServletRequest request); static String getSuffixSegment(final SlingHttpServletRequest request, int index); static String getSuffix(final SlingHttpServletRequest request); static String getFirstSuffixSegment(final SlingHttpServletRequest request); static String getLastSuffixSegment(final SlingHttpServletRequest request);  }### Answer:
@Test public void testGetQueryParam_HttpServletRequest_String() { ResourceResolver resourceResolver = context.resourceResolver(); MockSlingHttpServletRequest request = context.request(); request.setResource(resourceResolver.getResource("/apple/macbookair")); MockRequestPathInfo requestPathInfo = (MockRequestPathInfo)request.getRequestPathInfo(); requestPathInfo.setSelectorString("show"); requestPathInfo.setExtension("html"); request.setQueryString("cpu=i7&ghz=2.4"); String key = "ghz"; String expResult = "2.4"; String result = PathInfoUtil.getQueryParam(request, key); assertEquals(expResult, result); }
@Test public void testGetQueryParam_withDefault() { ResourceResolver resourceResolver = context.resourceResolver(); MockSlingHttpServletRequest request = context.request(); request.setResource(resourceResolver.getResource("/apple/macbookair")); MockRequestPathInfo requestPathInfo = (MockRequestPathInfo)request.getRequestPathInfo(); requestPathInfo.setSelectorString("show"); requestPathInfo.setExtension("html"); request.setQueryString("cpu=i7&ghz=2.4"); String key = "ghz"; String expResult = "2.4"; String result = PathInfoUtil.getQueryParam(request, key, "3"); assertEquals(expResult, result); key = "doesnt-exist"; expResult = "3"; result = PathInfoUtil.getQueryParam(request, key, "3"); assertEquals(expResult, result); }