@Test public void testWithPrimitives() throws NoSuchMethodException { ParamConverterEngine engine = new ParamConverterEngine(); engine.converters = Collections.emptyList(); assertThat(engine.convertValue("1", Integer.class, null, null)).isEqualTo(1); assertThat(engine.convertValue("1", Integer.TYPE, null, null)).isEqualTo(1); assertThat(engine.convertValue(null, Integer.class, null, "1")).isEqualTo(1); assertThat(engine.convertValue("2", Long.class, null, null)).isEqualTo(2l); assertThat(engine.convertValue("2", Long.TYPE, null, null)).isEqualTo(2l); assertThat(engine.convertValue(null, Long.class, null, "2")).isEqualTo(2l); assertThat(engine.convertValue("3", Short.class, null, null)).isEqualTo((short) 3); assertThat(engine.convertValue("3", Short.TYPE, null, null)).isEqualTo((short) 3); assertThat(engine.convertValue(null, Short.class, null, "3")).isEqualTo((short) 3); assertThat(engine.convertValue("4", Byte.class, null, null)).isEqualTo((byte) 4); assertThat(engine.convertValue("4", Byte.TYPE, null, null)).isEqualTo((byte) 4); assertThat(engine.convertValue(null, Byte.class, null, "4")).isEqualTo((byte) 4); assertThat(engine.convertValue("5.5", Float.class, null, null)).isEqualTo(5.5f); assertThat(engine.convertValue("5.5", Float.TYPE, null, null)).isEqualTo(5.5f); assertThat(engine.convertValue(null, Float.class, null, "5.5")).isEqualTo(5.5f); assertThat(engine.convertValue("5.5", Double.class, null, null)).isEqualTo(5.5d); assertThat(engine.convertValue("5.5", Double.TYPE, null, null)).isEqualTo(5.5d); assertThat(engine.convertValue(null, Double.class, null, "5.5")).isEqualTo(5.5d); assertThat(engine.convertValue("a", Character.class, null, null)).isEqualTo('a'); assertThat(engine.convertValue("a", Character.TYPE, null, null)).isEqualTo('a'); assertThat(engine.convertValue(null, Character.class, null, "1")).isEqualTo('1'); assertThat(engine.convertValue("true", Boolean.class, null, null)).isTrue(); assertThat(engine.convertValue("on", Boolean.TYPE, null, null)).isTrue(); assertThat(engine.convertValue(null, Boolean.class, null, "yes")).isTrue(); assertThat(engine.convertValue("", Boolean.class, null, null)).isFalse(); assertThat(engine.convertValue(null, Boolean.TYPE, null, null)).isFalse(); assertThat(engine.convertValue(null, Boolean.class, null, "no")).isFalse(); }
@Override public <T> T convertValue(String input, Class<T> rawType, Type type, String defaultValue) throws IllegalArgumentException { if (rawType.isArray()) { List<String> args = getMultipleValues(input, defaultValue); return createArray(args, rawType.getComponentType()); } else if (Collection.class.isAssignableFrom(rawType)) { List<String> args = getMultipleValues(input, defaultValue); return createCollection(args, rawType, type); } else { return convertSingleValue(input, rawType, defaultValue); } }
ParamConverterEngine implements ParameterFactories { @Override public <T> T convertValue(String input, Class<T> rawType, Type type, String defaultValue) throws IllegalArgumentException { if (rawType.isArray()) { List<String> args = getMultipleValues(input, defaultValue); return createArray(args, rawType.getComponentType()); } else if (Collection.class.isAssignableFrom(rawType)) { List<String> args = getMultipleValues(input, defaultValue); return createCollection(args, rawType, type); } else { return convertSingleValue(input, rawType, defaultValue); } } }
ParamConverterEngine implements ParameterFactories { @Override public <T> T convertValue(String input, Class<T> rawType, Type type, String defaultValue) throws IllegalArgumentException { if (rawType.isArray()) { List<String> args = getMultipleValues(input, defaultValue); return createArray(args, rawType.getComponentType()); } else if (Collection.class.isAssignableFrom(rawType)) { List<String> args = getMultipleValues(input, defaultValue); return createCollection(args, rawType, type); } else { return convertSingleValue(input, rawType, defaultValue); } } ParamConverterEngine();  ParamConverterEngine(List<ParameterConverter> conv, List<ParameterFactory> fact); }
ParamConverterEngine implements ParameterFactories { @Override public <T> T convertValue(String input, Class<T> rawType, Type type, String defaultValue) throws IllegalArgumentException { if (rawType.isArray()) { List<String> args = getMultipleValues(input, defaultValue); return createArray(args, rawType.getComponentType()); } else if (Collection.class.isAssignableFrom(rawType)) { List<String> args = getMultipleValues(input, defaultValue); return createCollection(args, rawType, type); } else { return convertSingleValue(input, rawType, defaultValue); } } ParamConverterEngine();  ParamConverterEngine(List<ParameterConverter> conv, List<ParameterFactory> fact); @Override T convertValue(String input, Class<T> rawType, Type type, String defaultValue); @Override T convertValues(Collection<String> input, Class<T> rawType, Type type, String defaultValue); @Override T newInstance(Context context, Class<T> type); @Override Set<Class> getTypesHandledByFactories(); }
ParamConverterEngine implements ParameterFactories { @Override public <T> T convertValue(String input, Class<T> rawType, Type type, String defaultValue) throws IllegalArgumentException { if (rawType.isArray()) { List<String> args = getMultipleValues(input, defaultValue); return createArray(args, rawType.getComponentType()); } else if (Collection.class.isAssignableFrom(rawType)) { List<String> args = getMultipleValues(input, defaultValue); return createCollection(args, rawType, type); } else { return convertSingleValue(input, rawType, defaultValue); } } ParamConverterEngine();  ParamConverterEngine(List<ParameterConverter> conv, List<ParameterFactory> fact); @Override T convertValue(String input, Class<T> rawType, Type type, String defaultValue); @Override T convertValues(Collection<String> input, Class<T> rawType, Type type, String defaultValue); @Override T newInstance(Context context, Class<T> type); @Override Set<Class> getTypesHandledByFactories();  }