Validator { static String formatValue(Object value, QueryBuilderOptions options) { if(value == null) { return formatNull(); } else { if(value instanceof Number) { return formatNumber((Number) value); } else if(value instanceof String) { return formatString((String) value, options); } else if(value instanceof Boolean) { return formatBoolean((boolean) value); } else if(value instanceof QueryBuilder) { return formatQueryBuilder((QueryBuilder) value); } else if(value instanceof Expression) { return formatExpression((Expression) value); } else if(value instanceof Object[]) { return formatArray((Object[]) value, options); } else if(value instanceof Iterable<?>) { return formatIterable((Iterable<?>)value, options); } } return value.toString(); } private  Validator();   }
@Test public void formatStringWithoutQuotes() { QueryBuilderOptions options = new QueryBuilderOptions(); options.dontQuote = true; String fieldName = "NAME"; String actual = Validator.formatValue(fieldName, options); String expected = "NAME"; assertEquals(expected, actual); }
@Test public void formatStringWithQuotes() { QueryBuilderOptions options = new QueryBuilderOptions(); options.dontQuote = false; String fieldName = "NAME"; String actual = Validator.formatValue(fieldName, options); String expected = "'NAME'"; assertEquals(expected, actual); }
@Test public void formatStringReplaceQuutes() { QueryBuilderOptions options = new QueryBuilderOptions(); options.dontQuote = false; options.replaceSingleQuotes = true; options.singleQuoteReplacement = "#"; String fieldName = "N'A'ME"; String actual = Validator.formatValue(fieldName, options); String expected = "'N#A#ME'"; assertEquals(expected, actual); }