aboutsummaryrefslogtreecommitdiff
path: root/guava-tests/test/com/google/common/io/MoreFilesTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/test/com/google/common/io/MoreFilesTest.java')
-rw-r--r--guava-tests/test/com/google/common/io/MoreFilesTest.java53
1 files changed, 13 insertions, 40 deletions
diff --git a/guava-tests/test/com/google/common/io/MoreFilesTest.java b/guava-tests/test/com/google/common/io/MoreFilesTest.java
index 8076eb352..2b9c20fb6 100644
--- a/guava-tests/test/com/google/common/io/MoreFilesTest.java
+++ b/guava-tests/test/com/google/common/io/MoreFilesTest.java
@@ -23,6 +23,7 @@ import static com.google.common.jimfs.Feature.SYMBOLIC_LINKS;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
+import static org.junit.Assert.assertThrows;
import com.google.common.collect.ObjectArrays;
import com.google.common.jimfs.Configuration;
@@ -138,11 +139,7 @@ public class MoreFilesTest extends TestCase {
assertThat(source.sizeIfKnown()).isAbsent();
- try {
- source.size();
- fail();
- } catch (IOException expected) {
- }
+ assertThrows(IOException.class, () -> source.size());
}
}
@@ -157,11 +154,7 @@ public class MoreFilesTest extends TestCase {
assertThat(source.sizeIfKnown()).isAbsent();
- try {
- source.size();
- fail();
- } catch (IOException expected) {
- }
+ assertThrows(IOException.class, () -> source.size());
}
}
@@ -190,11 +183,7 @@ public class MoreFilesTest extends TestCase {
assertThat(source.sizeIfKnown()).isAbsent();
- try {
- source.size();
- fail();
- } catch (IOException expected) {
- }
+ assertThrows(IOException.class, () -> source.size());
}
}
@@ -311,24 +300,14 @@ public class MoreFilesTest extends TestCase {
Path file = root().resolve("parent/nonexistent.file");
Path parent = file.getParent();
assertFalse(Files.exists(parent));
- try {
- MoreFiles.createParentDirectories(file);
- // Cleanup in case parent creation was [erroneously] successful.
- Files.delete(parent);
- fail("expected exception");
- } catch (IOException expected) {
- }
+ assertThrows(IOException.class, () -> MoreFiles.createParentDirectories(file));
}
public void testCreateParentDirectories_nonDirectoryParentExists() throws IOException {
Path parent = createTempFile();
assertTrue(Files.isRegularFile(parent));
Path file = parent.resolve("foo");
- try {
- MoreFiles.createParentDirectories(file);
- fail();
- } catch (IOException expected) {
- }
+ assertThrows(IOException.class, () -> MoreFiles.createParentDirectories(file));
}
public void testCreateParentDirectories_symlinkParentExists() throws IOException {
@@ -435,8 +414,7 @@ public class MoreFilesTest extends TestCase {
static FileSystem newTestFileSystem(Feature... supportedFeatures) throws IOException {
FileSystem fs =
Jimfs.newFileSystem(
- Configuration.unix()
- .toBuilder()
+ Configuration.unix().toBuilder()
.setSupportedFeatures(ObjectArrays.concat(SYMBOLIC_LINKS, supportedFeatures))
.build());
Files.createDirectories(fs.getPath("dir/b/i/j/l"));
@@ -522,11 +500,7 @@ public class MoreFilesTest extends TestCase {
Path dir = fs.getPath("dir");
assertEquals(6, MoreFiles.listFiles(dir).size());
- try {
- method.delete(dir);
- fail("expected InsecureRecursiveDeleteException");
- } catch (InsecureRecursiveDeleteException expected) {
- }
+ assertThrows(InsecureRecursiveDeleteException.class, () -> method.delete(dir));
assertTrue(Files.exists(dir));
assertEquals(6, MoreFiles.listFiles(dir).size());
@@ -569,12 +543,11 @@ public class MoreFilesTest extends TestCase {
public void testDeleteRecursively_nonexistingFile_throwsNoSuchFileException() throws IOException {
try (FileSystem fs = newTestFileSystem()) {
- try {
- MoreFiles.deleteRecursively(fs.getPath("/work/nothere"), ALLOW_INSECURE);
- fail();
- } catch (NoSuchFileException expected) {
- assertThat(expected.getFile()).isEqualTo("/work/nothere");
- }
+ NoSuchFileException expected =
+ assertThrows(
+ NoSuchFileException.class,
+ () -> MoreFiles.deleteRecursively(fs.getPath("/work/nothere"), ALLOW_INSECURE));
+ assertThat(expected.getFile()).isEqualTo("/work/nothere");
}
}