aboutsummaryrefslogtreecommitdiff
path: root/guava-tests/test/com/google/common/io/ResourcesTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/test/com/google/common/io/ResourcesTest.java')
-rw-r--r--guava-tests/test/com/google/common/io/ResourcesTest.java42
1 files changed, 16 insertions, 26 deletions
diff --git a/guava-tests/test/com/google/common/io/ResourcesTest.java b/guava-tests/test/com/google/common/io/ResourcesTest.java
index b1a46c698..4344ed1ca 100644
--- a/guava-tests/test/com/google/common/io/ResourcesTest.java
+++ b/guava-tests/test/com/google/common/io/ResourcesTest.java
@@ -18,6 +18,7 @@ package com.google.common.io;
import static com.google.common.base.CharMatcher.whitespace;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
@@ -104,12 +105,10 @@ public class ResourcesTest extends IoTestCase {
}
public void testGetResource_notFound() {
- try {
- Resources.getResource("no such resource");
- fail();
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().isEqualTo("resource no such resource not found.");
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class, () -> Resources.getResource("no such resource"));
+ assertThat(e).hasMessageThat().isEqualTo("resource no such resource not found.");
}
public void testGetResource() {
@@ -117,16 +116,15 @@ public class ResourcesTest extends IoTestCase {
}
public void testGetResource_relativePath_notFound() {
- try {
- Resources.getResource(getClass(), "com/google/common/io/testdata/i18n.txt");
- fail();
- } catch (IllegalArgumentException e) {
- assertThat(e)
- .hasMessageThat()
- .isEqualTo(
- "resource com/google/common/io/testdata/i18n.txt"
- + " relative to com.google.common.io.ResourcesTest not found.");
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> Resources.getResource(getClass(), "com/google/common/io/testdata/i18n.txt"));
+ assertThat(e)
+ .hasMessageThat()
+ .isEqualTo(
+ "resource com/google/common/io/testdata/i18n.txt"
+ + " relative to com.google.common.io.ResourcesTest not found.");
}
public void testGetResource_relativePath() {
@@ -145,11 +143,7 @@ public class ResourcesTest extends IoTestCase {
// First check that we can't find it without setting the context loader.
// This is a sanity check that the test doesn't spuriously pass because
// the resource is visible to the system class loader.
- try {
- Resources.getResource(tempFile.getName());
- fail("Should get IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> Resources.getResource(tempFile.getName()));
// Now set the context loader to one that should find the resource.
URL baseUrl = tempFile.getParentFile().toURI().toURL();
@@ -170,11 +164,7 @@ public class ResourcesTest extends IoTestCase {
try {
Thread.currentThread().setContextClassLoader(null);
assertNotNull(Resources.getResource("com/google/common/io/testdata/i18n.txt"));
- try {
- Resources.getResource("no such resource");
- fail("Should get IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- }
+ assertThrows(IllegalArgumentException.class, () -> Resources.getResource("no such resource"));
} finally {
Thread.currentThread().setContextClassLoader(oldContextLoader);
}