|
11 | 11 |
|
12 | 12 | public class FileWriterExampleUnitTest { |
13 | 13 |
|
14 | | - private static final String FILE_NAME = "src/test/resources/FileWriterTest.txt"; |
15 | | - |
16 | 14 | @After |
17 | 15 | public void tearDown() throws IOException { |
18 | | - Files.delete(Path.of(FILE_NAME)); |
| 16 | + Files.delete(Path.of("src/test/resources/FileWriterTest.txt")); |
19 | 17 | } |
20 | 18 |
|
21 | 19 | @Test |
22 | 20 | public void testWriteString() throws IOException { |
23 | | - try (FileWriter fileWriter = new FileWriter(FILE_NAME)) { |
| 21 | + try (FileWriter fileWriter = new FileWriter("src/test/resources/FileWriterTest.txt")) { |
24 | 22 | fileWriter.write("Hello Folks!"); |
25 | 23 | } |
26 | | - Assert.assertEquals("Hello Folks!", new String(Files.readAllBytes(Path.of(FILE_NAME)))); |
| 24 | + Assert.assertEquals("Hello Folks!", new String(Files.readAllBytes(Path.of("src/test/resources/FileWriterTest.txt")))); |
27 | 25 | } |
28 | 26 |
|
29 | 27 | @Test |
30 | 28 | public void testAppendString() throws IOException { |
31 | | - try (FileWriter fileWriter = new FileWriter(FILE_NAME)) { |
| 29 | + try (FileWriter fileWriter = new FileWriter("src/test/resources/FileWriterTest.txt")) { |
32 | 30 | fileWriter.write("Hello Folks!"); |
33 | 31 | } |
34 | 32 | // using another try with resources to reopen the file in append mode |
35 | | - try (FileWriter fileWriter = new FileWriter(FILE_NAME, true)) { |
| 33 | + try (FileWriter fileWriter = new FileWriter("src/test/resources/FileWriterTest.txt", true)) { |
36 | 34 | fileWriter.write("Hello Folks Again!"); |
37 | 35 | } |
38 | 36 |
|
39 | | - Assert.assertEquals("Hello Folks!" + "Hello Folks Again!", new String(Files.readAllBytes(Path.of(FILE_NAME)))); |
| 37 | + Assert.assertEquals("Hello Folks!" + "Hello Folks Again!", new String(Files.readAllBytes(Path.of("src/test/resources/FileWriterTest.txt")))); |
40 | 38 | } |
41 | 39 |
|
42 | 40 | @Test |
43 | 41 | public void testWriteCharArray() throws IOException { |
44 | | - try (FileWriter fileWriter = new FileWriter(FILE_NAME)) { |
| 42 | + try (FileWriter fileWriter = new FileWriter("src/test/resources/FileWriterTest.txt")) { |
45 | 43 | fileWriter.write("Hello Folks!".toCharArray()); |
46 | 44 | } |
47 | | - Assert.assertEquals("Hello Folks!", new String(Files.readAllBytes(Path.of(FILE_NAME)))); |
| 45 | + Assert.assertEquals("Hello Folks!", new String(Files.readAllBytes(Path.of("src/test/resources/FileWriterTest.txt")))); |
48 | 46 | } |
49 | 47 | } |
0 commit comments