diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PropertyParserTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PropertyParserTest.java new file mode 100644 index 0000000..9b78740 --- /dev/null +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/PropertyParserTest.java @@ -0,0 +1,93 @@ +package de.staropensource.sosengine.base.srctests.utility; + +import de.staropensource.sosengine.base.utility.PropertyParser; +import de.staropensource.sosengine.unittests.UnitLogger; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Test the class {@link PropertyParser}. + */ +@DisplayName("PropertyParser") +class PropertyParserTest { + /** + * The {@link UnitLogger} for this instance. + */ + private final UnitLogger logger = new UnitLogger(getClass()); + + /** + * Tests the method {@code getString}. + */ + @ParameterizedTest + @DisplayName("getString") + @CsvSource({ + "testprop, success :)", + "very_nice_test, indeed", + "hello, Hello World!", + "a.property.mightLookLikeThis, some value" + }) + void testGetString(String propertyName, String propertyValue) { + logger.testCall("testGetString", propertyName, propertyValue); + + Properties properties = new Properties(); + properties.setProperty(propertyName, propertyValue); + + String result = new PropertyParser(properties).getString(propertyName); + assertEquals(propertyValue, result, "Result \"" + result + "\" does not match expected output \"" + propertyValue + "\""); + } + + /** + * Tests the method {@code getBoolean}. + */ + @ParameterizedTest + @DisplayName("getBoolean") + @CsvSource({ + "invalid_bool, asd, false", + "should.be.true, true, true", + "falsified, false, false", + "bit_no, 0, false", + "bit_yes, 1, true", + "no_a_bit, 2, false", + "yeah, yes, true", + "nah, no, false", + }) + void testGetBoolean(String propertyName, String propertyValue, boolean expected) { + logger.testCall("testGetBoolean", propertyName, propertyValue, expected); + + Properties properties = new Properties(); + properties.setProperty(propertyName, propertyValue); + + Boolean result = new PropertyParser(properties).getBoolean(propertyName); + assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\""); + } + + /** + * Tests the method {@code getByte}. + */ + @ParameterizedTest + @DisplayName("getByte") + @CsvSource({ + "invalid_bool, asd, false", + "should.be.true, true, true", + "falsified, false, false", + "bit_no, 0, false", + "bit_yes, 1, true", + "no_a_bit, 2, false", + "yeah, yes, true", + "nah, no, false", + }) + void testGetByte(String propertyName, String propertyValue, boolean expected) { + logger.testCall("testGetBoolean", propertyName, propertyValue, expected); + + Properties properties = new Properties(); + properties.setProperty(propertyName, propertyValue); + + Boolean result = new PropertyParser(properties).getBoolean(propertyName); + assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\""); + } +}