### Question:
PropertyUtil { public static <T, E extends Exception> T readSystemProperty(String propertyName, T defaultValue, PropertyParser<T, E> parser) { String strValue = null; try { strValue = System.getProperty(propertyName); if (strValue == null) { LOGGER.debug("Property: {} was not configured. Default value will be used instead: {}", propertyName, defaultValue); return defaultValue; } return parser.parse(strValue); } catch (Exception e) { LOGGER.error("An error was produced while parsing " + propertyName + " value from string: " + strValue + ", default value: " + defaultValue + " will be used instead.", e); return defaultValue; } } private  PropertyUtil(); static T readSystemProperty(String propertyName,
                                                                T defaultValue,
                                                                PropertyParser<T, E> parser);  }### Answer:
@Test public void readySystemPropertyWithValueSetAndParser() { System.setProperty(TEST_PROPERTY, VALUE.toString()); Integer result = PropertyUtil.readSystemProperty(TEST_PROPERTY, DEFAULT_VALUE, Integer::parseInt); assertEquals(VALUE, result, 0); result = PropertyUtil.readSystemProperty(TEST_PROPERTY, null, Integer::parseInt); assertEquals(VALUE, result, 0); }
@Test public void readySystemPropertyWithNoValueButDefaultSet() { Integer result = PropertyUtil.readSystemProperty(TEST_PROPERTY, DEFAULT_VALUE, Integer::parseInt); assertEquals(DEFAULT_VALUE, result, 0); result = PropertyUtil.readSystemProperty(TEST_PROPERTY, DEFAULT_VALUE, Integer::parseInt); assertEquals(DEFAULT_VALUE, result, 0); }
@Test public void readySystemPropertyWithValueSetButParsingError() { System.setProperty(TEST_PROPERTY, "VALUE"); Integer result = PropertyUtil.readSystemProperty(TEST_PROPERTY, DEFAULT_VALUE, Integer::parseInt); assertEquals(DEFAULT_VALUE, result, 0); result = PropertyUtil.readSystemProperty(TEST_PROPERTY, null, Integer::parseInt); assertNull(result); }
@Test public void readySystemPropertyWithNoParser() { Integer result = PropertyUtil.readSystemProperty(TEST_PROPERTY, DEFAULT_VALUE, null); assertEquals(DEFAULT_VALUE, result, 0); System.setProperty(TEST_PROPERTY, VALUE.toString()); result = PropertyUtil.readSystemProperty(TEST_PROPERTY, null, null); assertNull(result); }