### Question:
PropertyValueConverter implements AttributeConverter<Object, String> { @Override public Object convertToEntityAttribute(String dbData) { if ("true".equalsIgnoreCase(dbData)) { return true; } else if ("false".equalsIgnoreCase(dbData)) { return false; } else if (NumberUtils.isParsable(dbData)) { if (NumberUtils.isDigits(dbData) || (dbData.startsWith("-") && NumberUtils.isDigits(dbData.substring(1)))) { return Long.parseLong(dbData); } else { return Double.parseDouble(dbData); } } return dbData; }  @Override String convertToDatabaseColumn(Object attribute); @Override Object convertToEntityAttribute(String dbData);  }### Answer:
@Test public void convertToEntityAttribute_convertsToString() { String testValue = "test"; Object convertedValue = converter.convertToEntityAttribute(testValue); assertTrue(convertedValue instanceof String); assertTrue(testValue.equals(convertedValue)); }
@Test public void convertToEntityAttribute_convertsToLong() { String testValue = "42"; String negativeTestValue = "-42"; Object convertedValue = converter.convertToEntityAttribute(testValue); Object convertedNegativeValue = converter.convertToEntityAttribute(negativeTestValue); assertTrue(convertedValue instanceof Long); assertTrue(((Long) convertedValue) == 42); assertTrue(convertedNegativeValue instanceof Long); assertTrue(((Long) convertedNegativeValue) == -42); }
@Test public void convertToEntityAttribute_convertsToDouble() { String testValue = "17.42"; String negativeTestValue = "-17.42"; Object convertedValue = converter.convertToEntityAttribute(testValue); Object convertedNegativeValue = converter.convertToEntityAttribute(negativeTestValue); assertTrue(convertedValue instanceof Double); double val = Double.valueOf((Double) convertedValue); assertTrue(Math.abs(17.42 - val) <= 1E-8); assertTrue(convertedNegativeValue instanceof Double); val = Double.valueOf((Double) convertedNegativeValue); assertTrue(Math.abs(17.42 + val) <= 1E-8); }
@Test public void convertToEntityAttribute_convertsToBoolean() { String testValue = "true"; String testValueCaseInsensitive = "faLSe"; Object convertedValue = converter.convertToEntityAttribute(testValue); Object convertedValueCaseInsensitive = converter.convertToEntityAttribute(testValueCaseInsensitive); assertTrue(convertedValue instanceof Boolean); assertTrue(((Boolean) convertedValue) == true); assertTrue(convertedValueCaseInsensitive instanceof Boolean); assertTrue(((Boolean) convertedValueCaseInsensitive) == false); }