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