diff --git a/database/belisarius.db b/database/belisarius.db index d0f3e02..ebf3140 100644 Binary files a/database/belisarius.db and b/database/belisarius.db differ diff --git a/properties/login.properties b/properties/login.example.properties similarity index 100% rename from properties/login.properties rename to properties/login.example.properties diff --git a/src/main/java/bugs/stackoverflow/belisarius/services/PropertyService.java b/src/main/java/bugs/stackoverflow/belisarius/services/PropertyService.java index 29b64f0..cb4d3e3 100644 --- a/src/main/java/bugs/stackoverflow/belisarius/services/PropertyService.java +++ b/src/main/java/bugs/stackoverflow/belisarius/services/PropertyService.java @@ -1,5 +1,6 @@ package bugs.stackoverflow.belisarius.services; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; @@ -10,23 +11,26 @@ import org.slf4j.LoggerFactory; public class PropertyService { - private static final Logger LOGGER = LoggerFactory.getLogger(PropertyService.class); private Properties prop; public PropertyService() { - try (FileInputStream propertiesFis = new FileInputStream(FileUtils.LOGIN_PROPERTIES_FILE)) { - prop = new Properties(); - prop.load(propertiesFis); - } catch (IOException exception) { - LOGGER.info( - "IOException occurred while loading properties from " + FileUtils.LOGIN_PROPERTIES_FILE, - exception - ); + File propertiesFile = new File(FileUtils.LOGIN_PROPERTIES_FILE); + + // for testing + if (propertiesFile.isFile()) { + loadProperties(FileUtils.LOGIN_PROPERTIES_FILE); + } else { + loadProperties(FileUtils.LOGIN_PROPERTIES_EXAMPLE_FILE); } } + // added for testing + public PropertyService(String filename) { + loadProperties(filename); + } + public String getProperty(String name) { String property = prop.getProperty(name); @@ -36,4 +40,16 @@ public String getProperty(String name) { return property; } + + private void loadProperties(String filename) { + try (FileInputStream propertiesFis = new FileInputStream(filename)) { + prop = new Properties(); + prop.load(propertiesFis); + } catch (IOException exception) { + LOGGER.info( + "IOException occurred while loading properties from " + filename, + exception + ); + } + } } diff --git a/src/main/java/bugs/stackoverflow/belisarius/utils/FileUtils.java b/src/main/java/bugs/stackoverflow/belisarius/utils/FileUtils.java index afd09c1..f667030 100644 --- a/src/main/java/bugs/stackoverflow/belisarius/utils/FileUtils.java +++ b/src/main/java/bugs/stackoverflow/belisarius/utils/FileUtils.java @@ -14,6 +14,7 @@ public class FileUtils { public static final String LOGIN_PROPERTIES_FILE = "./properties/login.properties"; + public static final String LOGIN_PROPERTIES_EXAMPLE_FILE = "./properties/login.example.properties"; public static final Path OFFENSIVE_WORDS_FILE = Paths.get("./ini/OffensiveWords.csv"); public static final Path BLACKLISTED_WORDS_FILE = Paths.get("./ini/BlacklistedWords.csv"); public static final Path REASONS_FILE = Paths.get("./ini/Reasons.csv"); diff --git a/src/test/java/bugs/stackoverflow/belisarius/services/PropertyServiceTest.java b/src/test/java/bugs/stackoverflow/belisarius/services/PropertyServiceTest.java index bb9c39f..90b2db8 100644 --- a/src/test/java/bugs/stackoverflow/belisarius/services/PropertyServiceTest.java +++ b/src/test/java/bugs/stackoverflow/belisarius/services/PropertyServiceTest.java @@ -3,11 +3,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import bugs.stackoverflow.belisarius.services.PropertyService; +import bugs.stackoverflow.belisarius.utils.FileUtils; import org.junit.jupiter.api.Test; public class PropertyServiceTest { - private final PropertyService propertyService = new PropertyService(); + private final PropertyService propertyService = new PropertyService(FileUtils.LOGIN_PROPERTIES_EXAMPLE_FILE); @Test public void getPropertyTest() { diff --git a/src/test/java/bugs/stackoverflow/belisarius/utils/FileUtilsTest.java b/src/test/java/bugs/stackoverflow/belisarius/utils/FileUtilsTest.java index 52cd3ad..347a165 100644 --- a/src/test/java/bugs/stackoverflow/belisarius/utils/FileUtilsTest.java +++ b/src/test/java/bugs/stackoverflow/belisarius/utils/FileUtilsTest.java @@ -16,7 +16,7 @@ public class FileUtilsTest { private final PropertyService propertyService = new PropertyService(); - private final Path propertiesFilePath = Paths.get(FileUtils.LOGIN_PROPERTIES_FILE); + private final Path propertiesFilePath = Paths.get(FileUtils.LOGIN_PROPERTIES_EXAMPLE_FILE); @Test public void readFileTest() {