### Question:
UriResourcePathUtils { public static String addStaticQueryParamtersToRequest(final Request<?> request, final String uriResourcePath) { if (request == null || uriResourcePath == null) { return null; } String resourcePath = uriResourcePath; int index = resourcePath.indexOf("?"); if (index != -1) { String queryString = resourcePath.substring(index + 1); resourcePath = resourcePath.substring(0, index); for (String s : queryString.split("[;&]")) { index = s.indexOf("="); if (index != -1) { request.addParameter(s.substring(0, index), s.substring(index + 1)); } else { request.addParameter(s, (String)null); } } } return resourcePath; }  static String addStaticQueryParamtersToRequest(final Request<?> request,
                                                        final String uriResourcePath);  }### Answer:
@Test public void request_null_returns_null(){ Assert.assertNull(UriResourcePathUtils.addStaticQueryParamtersToRequest(null, "foo")); }
@Test public void uri_resource_path_null_returns_null(){ Assert.assertNull(UriResourcePathUtils .addStaticQueryParamtersToRequest(new DefaultRequest<Object> (null , null), null)); }
@Test public void uri_resource_path_doesnot_have_static_query_params_returns_uri_resource_path(){ final String uriResourcePath = "/foo/bar"; Assert.assertEquals(uriResourcePath, UriResourcePathUtils .addStaticQueryParamtersToRequest(new DefaultRequest<Object> (null, null), uriResourcePath)); }
@Test public void uri_resource_path_ends_with_question_mark_returns_path_removed_with_question_mark(){ final String expectedResourcePath = "/foo/bar"; final String pathWithEmptyStaticQueryParams = expectedResourcePath + "?"; Assert.assertEquals(expectedResourcePath, UriResourcePathUtils .addStaticQueryParamtersToRequest(new DefaultRequest<Object> (null, null), pathWithEmptyStaticQueryParams)); }
@Test public void queryparam_value_empty_adds_parameter_with_empty_string_to_request() { final String uriResourcePath = "/foo/bar"; final String uriResourcePathWithParams = uriResourcePath + "?param1="; final Request<Object> request = new DefaultRequest<Object> (null, null); Assert.assertEquals(uriResourcePath, UriResourcePathUtils .addStaticQueryParamtersToRequest(request, uriResourcePathWithParams)); Assert.assertTrue(request.getParameters().containsKey("param1")); Assert.assertEquals(Arrays.asList(""), request.getParameters().get("param1")); }
@Test public void static_queryparams_in_path_added_to_request(){ final String uriResourcePath = "/foo/bar"; final String uriResourcePathWithParams = uriResourcePath + "?param1=value1&param2=value2"; final Request<Object> request = new DefaultRequest<Object> (null, null); Assert.assertEquals(uriResourcePath, UriResourcePathUtils .addStaticQueryParamtersToRequest(request, uriResourcePathWithParams)); Assert.assertTrue(request.getParameters().containsKey("param1")); Assert.assertTrue(request.getParameters().containsKey("param2")); Assert.assertEquals(Arrays.asList("value1"), request.getParameters().get("param1")); Assert.assertEquals(Arrays.asList("value2"), request.getParameters().get("param2")); }
@Test public void queryparam_without_value_returns_list_containing_null_value() { final String uriResourcePath = "/foo/bar"; final String uriResourcePathWithParams = uriResourcePath + "?param"; final Request<Object> request = new DefaultRequest<Object>(null, null); Assert.assertEquals(uriResourcePath, UriResourcePathUtils.addStaticQueryParamtersToRequest(request, uriResourcePathWithParams)); Assert.assertTrue(request.getParameters().containsKey("param")); Assert.assertEquals(Arrays.asList((String)null), request.getParameters().get("param")); }