|
8 | 8 | import java.nio.file.Path; |
9 | 9 | import java.nio.file.Paths; |
10 | 10 |
|
| 11 | +import org.junit.Before; |
11 | 12 | import org.junit.Test; |
12 | 13 |
|
13 | 14 | public class FileCopierTest { |
| 15 | + File original =new File("src/test/resources/original.txt"); |
| 16 | + @Before |
| 17 | + public void init() throws IOException{ |
| 18 | + if(!original.exists()) |
| 19 | + Files.createFile(original.toPath()); |
| 20 | + } |
| 21 | + @Test |
| 22 | + public void givenIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
| 23 | + File copied = new File("src/test/resources/copiedWithIo.txt"); |
| 24 | + copied = FileCopier.copyWithIO(original, copied); |
| 25 | + assertTrue(copied.exists()); |
| 26 | + assertTrue(Files.readAllLines(original.toPath()) |
| 27 | + .equals(Files.readAllLines(copied.toPath()))); |
| 28 | + } |
14 | 29 |
|
15 | | - @Test |
16 | | - public void givenIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
17 | | - File copied = new File("src/test/resources/copiedWithIo.txt"); |
18 | | - File original = new File("src/test/resources/original.txt"); |
19 | | - copied = FileCopier.copyWithIO(original, copied); |
20 | | - assertTrue(copied.exists()); |
21 | | - assertTrue(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); |
22 | | - } |
| 30 | + @Test |
| 31 | + public void givenCommonsIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
| 32 | + File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); |
| 33 | + copied = FileCopier.copyWithCommonsIO(original, copied); |
| 34 | + assertTrue(copied.exists()); |
| 35 | + assertTrue(Files.readAllLines(original.toPath()) |
| 36 | + .equals(Files.readAllLines(copied.toPath()))); |
| 37 | + } |
23 | 38 |
|
24 | | - @Test |
25 | | - public void givenCommonsIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
26 | | - File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); |
27 | | - File original = new File("src/test/resources/original.txt"); |
28 | | - copied = FileCopier.copyWithCommonsIO(original, copied); |
29 | | - assertTrue(copied.exists()); |
30 | | - assertTrue(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); |
31 | | - } |
32 | | - |
33 | | - @Test |
34 | | - public void givenNIO2_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
35 | | - Path copied = Paths.get("src/test/resources/copiedWithNio.txt"); |
36 | | - Path original = Paths.get("src/test/resources/original.txt"); |
37 | | - copied = FileCopier.copyWithNio(original, copied); |
38 | | - assertTrue(Files.exists(copied)); |
39 | | - assertTrue(Files.readAllLines(original).equals(Files.readAllLines(copied))); |
40 | | - } |
| 39 | + @Test |
| 40 | + public void givenNIO2_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
| 41 | + Path copied = Paths.get("src/test/resources/copiedWithNio.txt"); |
| 42 | + Path originalPath = original.toPath(); |
| 43 | + copied = FileCopier.copyWithNio(originalPath, copied); |
| 44 | + assertTrue(Files.exists(copied)); |
| 45 | + assertTrue(Files.readAllLines(originalPath) |
| 46 | + .equals(Files.readAllLines(copied))); |
| 47 | + } |
41 | 48 | } |
0 commit comments