Skip to content

Commit 8b2d647

Browse files
committed
BAEL-1308 - test modifications
1 parent f7e92e3 commit 8b2d647

1 file changed

Lines changed: 32 additions & 25 deletions

File tree

‎core-java/src/test/java/com/baeldung/copyfiles/FileCopierTest.java‎

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,41 @@
88
import java.nio.file.Path;
99
import java.nio.file.Paths;
1010

11+
import org.junit.Before;
1112
import org.junit.Test;
1213

1314
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+
}
1429

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+
}
2338

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+
}
4148
}

0 commit comments

Comments
 (0)