### Question:
StringToIntegerConverterFactory implements TypeConverterFactory<String, Integer> { @Override public TypeConverter<String, Integer> createTypeConverter() { return new NumberTypeConverter<String, Integer>() { @Override protected Integer doConvert(String value) { if (numberFormat != null) { try { final Number number = numberFormat.parse(value.trim()); if (isPercentage()) { return (int) (number.doubleValue() * 100); } else { return number.intValue(); } } catch (ParseException e) { throw new TypeConverterException("Failed to decode Integer value '" + value + "' using NumberFormat instance " + numberFormat + ".", e); } } else { try { return Integer.parseInt(value.trim()); } catch (NumberFormatException e) { throw new TypeConverterException("Failed to decode Integer value '" + value + "'.", e); } } } }; }  @Override TypeConverter<String, Integer> createTypeConverter(); @Override TypeConverterDescriptor<Class<String>, Class<Integer>> getTypeConverterDescriptor();  }### Answer:
@Test public void test_empty_ok_value() { StringToIntegerConverterFactory stringToIntegerConverterFactory = new StringToIntegerConverterFactory(); assertEquals(new Integer(1), stringToIntegerConverterFactory.createTypeConverter().convert("1")); }
@Test public void test_empty_data_string() { StringToIntegerConverterFactory stringToIntegerConverterFactory = new StringToIntegerConverterFactory(); try { stringToIntegerConverterFactory.createTypeConverter().convert(""); fail("Expected DataDecodeException"); } catch (TypeConverterException e) { assertEquals("Failed to decode Integer value ''.", e.getMessage()); } }
@Test public void test_decode_locale_config() { StringToIntegerConverterFactory stringToIntegerConverterFactory = new StringToIntegerConverterFactory(); Properties config = new Properties(); config.setProperty(NumberTypeConverter.LOCALE, "de-DE"); TypeConverter<String, Integer> typeConverter = stringToIntegerConverterFactory.createTypeConverter(); ((Configurable) typeConverter).setConfiguration(config); Integer integerVal = typeConverter.convert("1234,45"); assertEquals(new Integer(1234), integerVal); }
@Test public void test_decode_format_config_01() { StringToIntegerConverterFactory stringToIntegerConverterFactory = new StringToIntegerConverterFactory(); Properties config = new Properties(); config.setProperty(NumberTypeConverter.FORMAT, "#,###.##"); TypeConverter<String, Integer> typeConverter = stringToIntegerConverterFactory.createTypeConverter(); ((Configurable) typeConverter).setConfiguration(config); Integer integerVal = typeConverter.convert("1,234.45"); assertEquals(new Integer(1234), integerVal); }
@Test public void test_decode_format_config_02() { StringToIntegerConverterFactory stringToIntegerConverterFactory = new StringToIntegerConverterFactory(); Properties config = new Properties(); config.setProperty(NumberTypeConverter.FORMAT, "#%"); TypeConverter<String, Integer> typeConverter = stringToIntegerConverterFactory.createTypeConverter(); ((Configurable) typeConverter).setConfiguration(config); Integer integerVal = typeConverter.convert("30%"); assertEquals(new Integer(30), integerVal); }