Skip to content

Commit 5ddb661

Browse files
authored
fix: create login.example.properties
1 parent 3668d2f commit 5ddb661

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

database/belisarius.db

0 Bytes
Binary file not shown.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package bugs.stackoverflow.belisarius.services;
22

3+
import java.io.File;
34
import java.io.FileInputStream;
45
import java.io.IOException;
56
import java.util.Properties;
@@ -10,23 +11,26 @@
1011
import org.slf4j.LoggerFactory;
1112

1213
public class PropertyService {
13-
1414
private static final Logger LOGGER = LoggerFactory.getLogger(PropertyService.class);
1515

1616
private Properties prop;
1717

1818
public PropertyService() {
19-
try (FileInputStream propertiesFis = new FileInputStream(FileUtils.LOGIN_PROPERTIES_FILE)) {
20-
prop = new Properties();
21-
prop.load(propertiesFis);
22-
} catch (IOException exception) {
23-
LOGGER.info(
24-
"IOException occurred while loading properties from " + FileUtils.LOGIN_PROPERTIES_FILE,
25-
exception
26-
);
19+
File propertiesFile = new File(FileUtils.LOGIN_PROPERTIES_FILE);
20+
21+
// for testing
22+
if (propertiesFile.isFile()) {
23+
loadProperties(FileUtils.LOGIN_PROPERTIES_FILE);
24+
} else {
25+
loadProperties(FileUtils.LOGIN_PROPERTIES_EXAMPLE_FILE);
2726
}
2827
}
2928

29+
// added for testing
30+
public PropertyService(String filename) {
31+
loadProperties(filename);
32+
}
33+
3034
public String getProperty(String name) {
3135
String property = prop.getProperty(name);
3236

@@ -36,4 +40,16 @@ public String getProperty(String name) {
3640

3741
return property;
3842
}
43+
44+
private void loadProperties(String filename) {
45+
try (FileInputStream propertiesFis = new FileInputStream(filename)) {
46+
prop = new Properties();
47+
prop.load(propertiesFis);
48+
} catch (IOException exception) {
49+
LOGGER.info(
50+
"IOException occurred while loading properties from " + filename,
51+
exception
52+
);
53+
}
54+
}
3955
}

src/main/java/bugs/stackoverflow/belisarius/utils/FileUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
public class FileUtils {
1616
public static final String LOGIN_PROPERTIES_FILE = "./properties/login.properties";
17+
public static final String LOGIN_PROPERTIES_EXAMPLE_FILE = "./properties/login.example.properties";
1718
public static final Path OFFENSIVE_WORDS_FILE = Paths.get("./ini/OffensiveWords.csv");
1819
public static final Path BLACKLISTED_WORDS_FILE = Paths.get("./ini/BlacklistedWords.csv");
1920
public static final Path REASONS_FILE = Paths.get("./ini/Reasons.csv");

src/test/java/bugs/stackoverflow/belisarius/services/PropertyServiceTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

55
import bugs.stackoverflow.belisarius.services.PropertyService;
6+
import bugs.stackoverflow.belisarius.utils.FileUtils;
67

78
import org.junit.jupiter.api.Test;
89

910
public class PropertyServiceTest {
10-
private final PropertyService propertyService = new PropertyService();
11+
private final PropertyService propertyService = new PropertyService(FileUtils.LOGIN_PROPERTIES_EXAMPLE_FILE);
1112

1213
@Test
1314
public void getPropertyTest() {

src/test/java/bugs/stackoverflow/belisarius/utils/FileUtilsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
public class FileUtilsTest {
1818
private final PropertyService propertyService = new PropertyService();
19-
private final Path propertiesFilePath = Paths.get(FileUtils.LOGIN_PROPERTIES_FILE);
19+
private final Path propertiesFilePath = Paths.get(FileUtils.LOGIN_PROPERTIES_EXAMPLE_FILE);
2020

2121
@Test
2222
public void readFileTest() {

0 commit comments

Comments
 (0)