11package de .doubleslash .usb_led_matrix ;
22
3+ import de .doubleslash .usb_led_matrix .model .AvailabilityStatus ;
4+ import javafx .scene .paint .Color ;
35import org .junit .jupiter .api .AfterEach ;
46import org .junit .jupiter .api .Test ;
57
68import java .io .File ;
9+ import java .io .FileReader ;
10+ import java .io .FileWriter ;
711import 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
917import static org .hamcrest .MatcherAssert .assertThat ;
1018import static org .hamcrest .CoreMatchers .is ;
19+ import static org .hamcrest .core .IsEqual .equalTo ;
1120import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
1221
1322class 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