Skip to content

Commit 0532349

Browse files
author
Grzegorz Piwowarek
committed
Refactor FileTest
1 parent f7525b8 commit 0532349

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

‎core-java/src/test/java/com/baeldung/java/nio2/FileTest.java‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
package com.baeldung.java.nio2;
22

3-
import static org.junit.Assert.assertFalse;
4-
import static org.junit.Assert.assertTrue;
3+
import org.junit.Test;
54

65
import java.io.IOException;
7-
import java.nio.file.DirectoryNotEmptyException;
8-
import java.nio.file.FileAlreadyExistsException;
9-
import java.nio.file.Files;
10-
import java.nio.file.NoSuchFileException;
11-
import java.nio.file.Path;
12-
import java.nio.file.Paths;
13-
import java.nio.file.StandardCopyOption;
6+
import java.nio.file.*;
147
import java.util.UUID;
158

16-
import org.junit.Test;
9+
import static org.junit.Assert.assertFalse;
10+
import static org.junit.Assert.assertTrue;
1711

1812
public class FileTest {
1913
private static final String HOME = System.getProperty("user.home");
@@ -158,16 +152,11 @@ public void givenPath_whenFailsToDeleteNonEmptyDir_thenCorrect() throws IOExcept
158152

159153
}
160154

161-
@Test
155+
@Test(expected = NoSuchFileException.class)
162156
public void givenInexistentFile_whenDeleteFails_thenCorrect() throws IOException {
163157
Path p = Paths.get(HOME + "/inexistentFile.txt");
164158
assertFalse(Files.exists(p));
165-
try {
166-
Files.delete(p);
167-
} catch (IOException e) {
168-
assertTrue(e instanceof NoSuchFileException);
169-
}
170-
159+
Files.delete(p);
171160
}
172161

173162
@Test

0 commit comments

Comments
 (0)