Skip to content

Commit d81e8a9

Browse files
committed
IPTE-149: Include new Test - shouldLoadSettingsSuccessfullyWhenFileExists
1 parent b5c690a commit d81e8a9

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/main/java/de/doubleslash/usb_led_matrix/model/AvailabilityStatus.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import javafx.scene.paint.Color;
44

55
public enum AvailabilityStatus {
6+
// @formatter:off
67
Available(Color.GREEN, "available"),
78
AvailableIdle(Color.GREEN, Available.propertyKey),
89
Away(Color.ORANGE, "away"),
@@ -12,6 +13,7 @@ public enum AvailabilityStatus {
1213
DoNotDisturb(Color.RED, "doNotDisturb"),
1314
Offline(Color.BLACK, null),
1415
PresenceUnknown(null, null);
16+
// @formatter:on
1517

1618
private Color color;
1719
private final String propertyKey;

src/test/java/de/doubleslash/usb_led_matrix/SettingsTest.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,50 @@
11
package de.doubleslash.usb_led_matrix;
22

3+
import de.doubleslash.usb_led_matrix.model.AvailabilityStatus;
4+
import javafx.scene.paint.Color;
35
import org.junit.jupiter.api.AfterEach;
46
import org.junit.jupiter.api.Test;
57

68
import java.io.File;
9+
import java.io.FileReader;
10+
import java.io.FileWriter;
711
import java.io.IOException;
12+
import java.nio.file.FileAlreadyExistsException;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
import java.nio.file.Paths;
816

917
import static org.hamcrest.MatcherAssert.assertThat;
1018
import static org.hamcrest.CoreMatchers.is;
19+
import static org.hamcrest.core.IsEqual.equalTo;
1120
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1221

1322
class SettingsTest {
14-
private final String fileName = Settings.filePath;
23+
private final String fileName = filePath;
24+
private static final String filePath = "settings.properties";
25+
private static final String fileContent =
26+
// @formatter:off
27+
"away=0xffa500ff\n"
28+
+ "doNotDisturb=0xff0000ff\n"
29+
+ "busy=0xff0000ff\n"
30+
+ "available=0x00ff00ff\n"
31+
+ "beRightBack=0xffa500ff\n";
32+
// @formatter:on
33+
34+
@Test
35+
void shouldLoadSettingsSuccessfullyWhenFileExists() {
36+
createPropertiesFile();
37+
38+
Settings.loadSettings();
39+
40+
assertThat(AvailabilityStatus.Available.getColor(), equalTo(Color.web("#00ff00ff")));
41+
assertThat(AvailabilityStatus.AvailableIdle.getColor(), equalTo(Color.web("#00ff00ff")));
42+
assertThat(AvailabilityStatus.Away.getColor(), equalTo(Color.web("#ffa500ff")));
43+
assertThat(AvailabilityStatus.BeRightBack.getColor(), equalTo(Color.web("#ffa500ff")));
44+
assertThat(AvailabilityStatus.Busy.getColor(), equalTo(Color.web("#ff0000ff")));
45+
assertThat(AvailabilityStatus.BusyIdle.getColor(), equalTo(Color.web("#ff0000ff")));
46+
assertThat(AvailabilityStatus.DoNotDisturb.getColor(), equalTo(Color.web("#ff0000ff")));
47+
}
1548

1649
@Test
1750
void shouldNotThrowNullPointerExceptionWhenSettingsFileExistsButPropertyIsMissing() throws IOException {
@@ -33,6 +66,17 @@ void shouldThrowExceptionWhenFileDoesNotExist() {
3366
assertDoesNotThrow(Settings::loadSettings);
3467
}
3568

69+
private void createPropertiesFile() {
70+
try {
71+
File file = new File(filePath);
72+
FileWriter fileWriter = new FileWriter(file);
73+
fileWriter.write(fileContent);
74+
fileWriter.close();
75+
} catch (IOException e) {
76+
e.printStackTrace();
77+
}
78+
}
79+
3680
@AfterEach
3781
private void deleteFileIfExists() {
3882
final File file = new File(fileName);

0 commit comments

Comments
 (0)