### Question:
UriInfoToApiQueryConverter { public ApiQuery convert(ApiQuery apiQuery, URI requestURI) { if (requestURI == null) { return apiQuery; } return convert(apiQuery, requestURI.getQuery()); } UriInfoToApiQueryConverter(); ApiQuery convert(ApiQuery apiQuery, URI requestURI); ApiQuery convert(ApiQuery apiQuery, UriInfo uriInfo); ApiQuery convert(ApiQuery apiQuery, String queryString); ApiQuery convert(UriInfo uriInfo);  }### Answer:
@Test public void testNonNullForNull() { assertTrue(QUERY_CONVERTER.convert(null) != null); }
@Test (expected = QueryParseException.class) public void testPreventionOfNegativeLimit() throws URISyntaxException { String queryString = "limit=-1"; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); QUERY_CONVERTER.convert(uriInfo); }
@Test(expected = QueryParseException.class) public void testPreventionOfNegativeOffset() throws URISyntaxException { String queryString = "offset=-1"; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); QUERY_CONVERTER.convert(uriInfo); }
@Test(expected = QueryParseException.class) public void testSelectorShouldFail() throws URISyntaxException { String queryString = "selector=:(students)"; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); QUERY_CONVERTER.convert(uriInfo); }
@Test(expected = QueryParseException.class) public void testInvalidSelector() { try { String queryString = "selector=true"; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); } catch (URISyntaxException urise) { assertTrue(false); } QUERY_CONVERTER.convert(uriInfo); }
@Test(expected = QueryParseException.class) public void testInvalidOffset() { try { String queryString = "offset=four"; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); } catch (URISyntaxException urise) { assertTrue(false); } QUERY_CONVERTER.convert(uriInfo); }
@Test(expected = QueryParseException.class) public void testInvalidLimit() { try { String queryString = "limit=four"; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); } catch (URISyntaxException urise) { assertTrue(false); } QUERY_CONVERTER.convert(uriInfo); }
@Test(expected = QueryParseException.class) public void testQueryStringMissingKey() { try { String queryString = "=4"; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); } catch (URISyntaxException urise) { assertTrue(false); } QUERY_CONVERTER.convert(uriInfo); }
@Test(expected = QueryParseException.class) public void testQueryStringMissingOperator() { try { String queryString = "key4"; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); } catch (URISyntaxException urise) { assertTrue(false); } QUERY_CONVERTER.convert(uriInfo); }
@Test(expected = QueryParseException.class) public void testQueryStringMissingValue() { try { String queryString = "key="; URI requestUri = new URI(URI_STRING + "?" + queryString); when(uriInfo.getRequestUri()).thenReturn(requestUri); } catch (URISyntaxException urise) { assertTrue(false); } QUERY_CONVERTER.convert(uriInfo); }