diff options
Diffstat (limited to 'guava-tests/test/com/google/common/io/CharSourceTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/io/CharSourceTest.java | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/guava-tests/test/com/google/common/io/CharSourceTest.java b/guava-tests/test/com/google/common/io/CharSourceTest.java index 787d744b7..cf305fd61 100644 --- a/guava-tests/test/com/google/common/io/CharSourceTest.java +++ b/guava-tests/test/com/google/common/io/CharSourceTest.java @@ -21,6 +21,7 @@ import static com.google.common.io.TestOption.CLOSE_THROWS; import static com.google.common.io.TestOption.OPEN_THROWS; import static com.google.common.io.TestOption.READ_THROWS; import static com.google.common.io.TestOption.WRITE_THROWS; +import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -210,11 +211,7 @@ public class CharSourceTest extends IoTestCase { public void testClosesOnErrors_copyingToCharSinkThatThrows() { for (TestOption option : EnumSet.of(OPEN_THROWS, WRITE_THROWS, CLOSE_THROWS)) { TestCharSource okSource = new TestCharSource(STRING); - try { - okSource.copyTo(new TestCharSink(option)); - fail(); - } catch (IOException expected) { - } + assertThrows(IOException.class, () -> okSource.copyTo(new TestCharSink(option))); // ensure reader was closed IF it was opened (depends on implementation whether or not it's // opened at all if sink.newWriter() throws). assertTrue( @@ -225,21 +222,13 @@ public class CharSourceTest extends IoTestCase { public void testClosesOnErrors_whenReadThrows() { TestCharSource failSource = new TestCharSource(STRING, READ_THROWS); - try { - failSource.copyTo(new TestCharSink()); - fail(); - } catch (IOException expected) { - } + assertThrows(IOException.class, () -> failSource.copyTo(new TestCharSink())); assertTrue(failSource.wasStreamClosed()); } public void testClosesOnErrors_copyingToWriterThatThrows() { TestCharSource okSource = new TestCharSource(STRING); - try { - okSource.copyTo(new TestWriter(WRITE_THROWS)); - fail(); - } catch (IOException expected) { - } + assertThrows(IOException.class, () -> okSource.copyTo(new TestWriter(WRITE_THROWS))); assertTrue(okSource.wasStreamClosed()); } @@ -362,7 +351,9 @@ public class CharSourceTest extends IoTestCase { } } - /** @return the number of exceptions that were suppressed on the expected thrown exception */ + /** + * @return the number of exceptions that were suppressed on the expected thrown exception + */ private static int runSuppressionFailureTest(CharSource in, CharSink out) { try { in.copyTo(out); |