QueryUtils { public static <T> T parseValue( Class<T> klass, Object objectValue ) { return parseValue( klass, null, objectValue ); }  static T parseValue( Class<T> klass, Object objectValue ); @SuppressWarnings( "unchecked" ) static T parseValue( Class<T> klass, Class<?> secondaryKlass, Object objectValue ); @SuppressWarnings( { "unchecked", "rawtypes" } ) static T getEnumValue( Class<T> klass, String value ); static Object parseValue( String value ); static String parseSelectFields( List<String> fields ); static String convertCollectionValue( String value ); static String parseFilterOperator( String operator, String value ); @Nonnull static List<Order> convertOrderStrings( @Nullable Collection<String> orders, @Nonnull Schema schema ); static T getSingleResult( TypedQuery<T> query );  }
@Test public void testParseValidEnum() { assertNotNull( QueryUtils.parseValue( ValueType.class, "INTEGER" ) ); assertNotNull( QueryUtils.parseValue( ValueType.class, "TEXT" ) ); }
@Test public void testParseValidInteger() { Integer value1 = QueryUtils.parseValue( Integer.class, "10" ); Integer value2 = QueryUtils.parseValue( Integer.class, "100" ); assertNotNull( value1 ); assertNotNull( value2 ); assertSame( 10, value1 ); assertSame( 100, value2 ); }
@Test( expected = QueryParserException.class ) public void testParseInvalidEnum() { QueryUtils.parseValue( ValueType.class, "INTEGER" ); QueryUtils.parseValue( ValueType.class, "ABC" ); }
@Test( expected = QueryParserException.class ) public void testInvalidInteger() { QueryUtils.parseValue( Integer.class, "1" ); QueryUtils.parseValue( Integer.class, "ABC" ); }
@Test( expected = QueryParserException.class ) public void testInvalidFloat() { QueryUtils.parseValue( Float.class, "1.2" ); QueryUtils.parseValue( Float.class, "ABC" ); }
@Test( expected = QueryParserException.class ) public void testInvalidDouble() { QueryUtils.parseValue( Double.class, "1.2" ); QueryUtils.parseValue( Double.class, "ABC" ); }
@Test( expected = QueryParserException.class ) public void testInvalidDate() { QueryUtils.parseValue( Date.class, "2014" ); QueryUtils.parseValue( Date.class, "ABC" ); }
@Test public void testParseValue() { assertEquals( "'abc'", QueryUtils.parseValue( "abc" ) ); assertEquals( "123", QueryUtils.parseValue( "123" ) ); }
@Test public void testParserNotFound() { final Class<User> nonSupportedClass = User.class; final String anyValue = "wewee-4343"; exceptionRule.expect( QueryParserException.class ); exceptionRule .expectMessage( "Unable to parse `" + anyValue + "` to `" + nonSupportedClass.getSimpleName() + "`." ); QueryUtils.parseValue( nonSupportedClass, anyValue ); }