QueryServiceUtil { public static <T> T getItem(QueryService<T, ?> s, QueryExpr itemExpr) { T item = findItem(s, itemExpr); if (item == null) { throw new IllegalArgumentException("No item found for expression " + itemExpr); } return item; } private  QueryServiceUtil(); static T getItem(QueryService<T, ?> s, QueryExpr itemExpr); static T findItem(QueryService<T, ?> s, QueryExpr itemExpr); @SuppressWarnings("unchecked") static List<T> findItems(QueryService<T, ?> s, QueryExpr itemExpr, int maxNumOfItems); static T findEqItem(QueryService<T, ?> s, QueryAttr qAttr, Object value);  }
@Test public void testGetItemOnIdQueryService() { assertEquals("2", QueryServiceUtil.getItem(idQueryService, new QueryExprCompare(TestBean.ATTR_NAME, CompOpEquals.class, "2")).toString()); }
@Test public void testGetItemOnPageQueryService() { assertEquals("2", QueryServiceUtil.getItem(pageQueryService, new QueryExprCompare(TestBean.ATTR_NAME, CompOpEquals.class, "2")).toString()); }
@Test(expected=IllegalArgumentException.class) public void testGetItemThrowsExceptionIfNoItemFound() { QueryServiceUtil.getItem(idQueryService, new QueryExprCompare(TestBean.ATTR_NAME, CompOpEquals.class, "Unknown")); }