Skip to content

Commit

Permalink
fix: create login.example.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Aug 28, 2024
1 parent 3668d2f commit 5ddb661
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
Binary file modified database/belisarius.db
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand All @@ -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
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5ddb661

Please sign in to comment.