Skip to content

Commit

Permalink
Add tests for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
huangsam committed Nov 30, 2024
1 parent c5b1fc2 commit 78d54aa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/huangsam/photohaul/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class Main {
private static final Logger LOG = getLogger(Main.class);
private static final Settings SETTINGS = new Settings();
private static final Settings SETTINGS = new Settings("config.properties");

public static void main(String[] args) {
PhotoPathVisitor pathVisitor = new PhotoPathVisitor();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/huangsam/photohaul/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
public class Settings {
private final Properties properties;

public Settings() {
public Settings(String name) {
properties = new Properties();
try (InputStream input = this.getClass().getClassLoader().getResourceAsStream("config.properties")) {
try (InputStream input = this.getClass().getClassLoader().getResourceAsStream(name)) {
properties.load(input);
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/config.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source.root=Pictures/Dummy PNG
target.root=Pictures/Dummy FIN
source.root=Pictures/Source
target.root=Pictures/Target
2 changes: 2 additions & 0 deletions src/main/resources/path-example.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source.root=Dummy/Source
target.root=Dummy/Target
19 changes: 19 additions & 0 deletions src/test/java/io/huangsam/photohaul/TestSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.huangsam.photohaul;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestSettings {
private static final Settings SETTINGS = new Settings("path-example.properties");

@Test
void testGetSourceRoot() {
assertTrue(SETTINGS.getSourceRoot().endsWith("Dummy/Source"));
}

@Test
void testGetTargetRoot() {
assertTrue(SETTINGS.getTargetRoot().endsWith("Dummy/Target"));
}
}

0 comments on commit 78d54aa

Please sign in to comment.