|
19 | 19 | import static org.assertj.core.api.Assertions.*; |
20 | 20 |
|
21 | 21 | public class FileCopierTest { |
22 | | - File original = new File("src/test/resources/original.txt"); |
| 22 | + File original = new File("src/test/resources/original.txt"); |
23 | 23 |
|
24 | | - @Before |
25 | | - public void init() throws IOException { |
26 | | - if (!original.exists()) |
27 | | - Files.createFile(original.toPath()); |
28 | | - } |
| 24 | + @Before |
| 25 | + public void init() throws IOException { |
| 26 | + if (!original.exists()) |
| 27 | + Files.createFile(original.toPath()); |
| 28 | + } |
29 | 29 |
|
30 | | - @Test |
31 | | - public void givenIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
32 | | - File copied = new File("src/test/resources/copiedWithIo.txt"); |
33 | | - try (InputStream in = new BufferedInputStream(new FileInputStream(original)); |
34 | | - OutputStream out = new BufferedOutputStream(new FileOutputStream(copied))) { |
35 | | - byte[] buffer = new byte[1024]; |
36 | | - int lengthRead; |
37 | | - while ((lengthRead = in.read(buffer)) > 0) { |
38 | | - out.write(buffer, 0, lengthRead); |
39 | | - out.flush(); |
40 | | - } |
41 | | - } |
42 | | - assertThat(copied).exists(); |
43 | | - assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); |
44 | | - } |
| 30 | + @Test |
| 31 | + public void givenIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
| 32 | + File copied = new File("src/test/resources/copiedWithIo.txt"); |
| 33 | + try (InputStream in = new BufferedInputStream(new FileInputStream(original)); OutputStream out = new BufferedOutputStream(new FileOutputStream(copied))) { |
| 34 | + byte[] buffer = new byte[1024]; |
| 35 | + int lengthRead; |
| 36 | + while ((lengthRead = in.read(buffer)) > 0) { |
| 37 | + out.write(buffer, 0, lengthRead); |
| 38 | + out.flush(); |
| 39 | + } |
| 40 | + } |
| 41 | + assertThat(copied).exists(); |
| 42 | + assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); |
| 43 | + } |
45 | 44 |
|
46 | | - @Test |
47 | | - public void givenCommonsIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
48 | | - File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); |
49 | | - FileUtils.copyFile(original, copied); |
50 | | - assertThat(copied).exists(); |
51 | | - assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); |
52 | | - } |
| 45 | + @Test |
| 46 | + public void givenCommonsIoAPI_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
| 47 | + File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); |
| 48 | + FileUtils.copyFile(original, copied); |
| 49 | + assertThat(copied).exists(); |
| 50 | + assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); |
| 51 | + } |
53 | 52 |
|
54 | | - @Test |
55 | | - public void givenNIO2_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
56 | | - Path copied = Paths.get("src/test/resources/copiedWithNio.txt"); |
57 | | - Path originalPath = original.toPath(); |
58 | | - Files.copy(originalPath, copied, StandardCopyOption.REPLACE_EXISTING); |
59 | | - assertThat(copied).exists(); |
60 | | - assertThat(Files.readAllLines(originalPath).equals(Files.readAllLines(copied))); |
61 | | - } |
| 53 | + @Test |
| 54 | + public void givenNIO2_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
| 55 | + Path copied = Paths.get("src/test/resources/copiedWithNio.txt"); |
| 56 | + Path originalPath = original.toPath(); |
| 57 | + Files.copy(originalPath, copied, StandardCopyOption.REPLACE_EXISTING); |
| 58 | + assertThat(copied).exists(); |
| 59 | + assertThat(Files.readAllLines(originalPath).equals(Files.readAllLines(copied))); |
| 60 | + } |
62 | 61 |
|
63 | | - @Test |
64 | | - public void givenGuava_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
65 | | - File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); |
66 | | - com.google.common.io.Files.copy(original, copied); |
67 | | - assertThat(copied).exists(); |
68 | | - assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); |
69 | | - } |
| 62 | + @Test |
| 63 | + public void givenGuava_whenCopied_thenCopyExistsWithSameContents() throws IOException { |
| 64 | + File copied = new File("src/test/resources/copiedWithApacheCommons.txt"); |
| 65 | + com.google.common.io.Files.copy(original, copied); |
| 66 | + assertThat(copied).exists(); |
| 67 | + assertThat(Files.readAllLines(original.toPath()).equals(Files.readAllLines(copied.toPath()))); |
| 68 | + } |
70 | 69 | } |
0 commit comments