66import org .junit .jupiter .api .Test ;
77
88import java .io .File ;
9- import java .io .FileReader ;
109import java .io .FileWriter ;
1110import 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 ;
1611
1712import static org .hamcrest .MatcherAssert .assertThat ;
1813import static org .hamcrest .CoreMatchers .is ;
1914import static org .hamcrest .core .IsEqual .equalTo ;
2015import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
2116
2217class SettingsTest {
23- private final String fileName = filePath ;
2418 private static final String filePath = "settings.properties" ;
2519 private static final String fileContent =
2620 // @formatter:off
2721 "away=0xffa500ff\n "
2822 + "doNotDisturb=0xff0000ff\n "
29- + "busy=0xff0000ff \n "
30- + "available=0x00ff00ff \n "
31- + "beRightBack=0xffa500ff \n " ;
23+ + "busy=0xff00000f \n "
24+ + "available=0x00ff0fff \n "
25+ + "beRightBack=0xffa550ff \n " ;
3226 // @formatter:on
3327
3428 @ Test
35- void shouldLoadSettingsSuccessfullyWhenFileExists () {
29+ void shouldLoadSettingsSuccessfullyWhenFileExists () throws IOException {
3630 createPropertiesFile ();
3731
3832 Settings .loadSettings ();
3933
40- assertThat (AvailabilityStatus .Available .getColor (), equalTo (Color .web ("#00ff00ff " )));
41- assertThat (AvailabilityStatus .AvailableIdle .getColor (), equalTo (Color .web ("#00ff00ff " )));
34+ assertThat (AvailabilityStatus .Available .getColor (), equalTo (Color .web ("#00ff0fff " )));
35+ assertThat (AvailabilityStatus .AvailableIdle .getColor (), equalTo (Color .web ("#00ff0fff " )));
4236 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 " )));
37+ assertThat (AvailabilityStatus .BeRightBack .getColor (), equalTo (Color .web ("#ffa550ff " )));
38+ assertThat (AvailabilityStatus .Busy .getColor (), equalTo (Color .web ("#ff00000f " )));
39+ assertThat (AvailabilityStatus .BusyIdle .getColor (), equalTo (Color .web ("#ff00000f " )));
4640 assertThat (AvailabilityStatus .DoNotDisturb .getColor (), equalTo (Color .web ("#ff0000ff" )));
4741 }
4842
4943 @ Test
5044 void shouldNotThrowNullPointerExceptionWhenSettingsFileExistsButPropertyIsMissing () throws IOException {
5145 //ARRANGE
52- final File file = new File (fileName );
46+ final File file = new File (filePath );
5347 file .createNewFile ();
5448
5549 //ACT+ASSERT
@@ -59,27 +53,23 @@ void shouldNotThrowNullPointerExceptionWhenSettingsFileExistsButPropertyIsMissin
5953 @ Test
6054 void shouldThrowExceptionWhenFileDoesNotExist () {
6155 //ARRANGE
62- final File file = new File (fileName );
56+ final File file = new File (filePath );
6357 assertThat (file .exists (), is (false ));
6458
6559 //ACT+ASSERT
6660 assertDoesNotThrow (Settings ::loadSettings );
6761 }
6862
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- }
63+ private void createPropertiesFile () throws IOException {
64+ File file = new File (filePath );
65+ FileWriter fileWriter = new FileWriter (file );
66+ fileWriter .write (fileContent );
67+ fileWriter .close ();
7868 }
7969
8070 @ AfterEach
8171 private void deleteFileIfExists () {
82- final File file = new File (fileName );
72+ final File file = new File (filePath );
8373 if (file .exists ()) {
8474 file .delete ();
8575 }
0 commit comments