|
21 | 21 | import java.io.IOException; |
22 | 22 | import java.io.StringReader; |
23 | 23 | import java.io.StringWriter; |
| 24 | +import java.nio.file.Files; |
| 25 | +import java.nio.file.Path; |
24 | 26 | import java.util.Arrays; |
25 | 27 |
|
26 | 28 | import org.junit.jupiter.api.Test; |
| 29 | +import org.junit.jupiter.api.io.TempDir; |
27 | 30 |
|
28 | 31 | import static org.assertj.core.api.Assertions.assertThat; |
29 | 32 |
|
@@ -87,4 +90,29 @@ void copyToString() throws IOException { |
87 | 90 | assertThat(result).isEqualTo(content); |
88 | 91 | } |
89 | 92 |
|
| 93 | + @Test |
| 94 | + void copyFile(@TempDir Path tempDir) throws IOException { |
| 95 | + Path source = tempDir.resolve("src"); |
| 96 | + Path target = tempDir.resolve("target"); |
| 97 | + Files.write(source, "content".getBytes()); |
| 98 | + int bytesWritten = FileCopyUtils.copy(source.toFile(), target.toFile()); |
| 99 | + assertThat(bytesWritten).isEqualTo(7); |
| 100 | + assertThat(target).exists(); |
| 101 | + assertThat(target).content().isEqualTo("content"); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + void copyFileToByteArray(@TempDir Path tempDir) throws IOException { |
| 106 | + Path source = tempDir.resolve("src"); |
| 107 | + Files.write(source, "content".getBytes()); |
| 108 | + assertThat(FileCopyUtils.copyToByteArray(source.toFile())).asString().isEqualTo("content"); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + void copyByteArrayToFile(@TempDir Path tempDir) throws IOException { |
| 113 | + Path target = tempDir.resolve("target"); |
| 114 | + FileCopyUtils.copy("content".getBytes(), target.toFile()); |
| 115 | + assertThat(target).exists(); |
| 116 | + assertThat(target).content().isEqualTo("content"); |
| 117 | + } |
90 | 118 | } |
0 commit comments