This is an automated email from the ASF dual-hosted git repository. sebb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new 3ea9a2e Try with resources/assert Throws 3ea9a2e is described below commit 3ea9a2ec77a4d8d559e8e568681cd9c155ef1dca Author: Sebb <s...@apache.org> AuthorDate: Fri Aug 7 23:06:02 2020 +0100 Try with resources/assert Throws --- .../io/output/FileWriterWithEncodingTest.java | 62 ++++++++-------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java b/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java index 7a283af..5a1d2e5 100644 --- a/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java +++ b/src/test/java/org/apache/commons/io/output/FileWriterWithEncodingTest.java @@ -18,6 +18,7 @@ package org.apache.commons.io.output; import static org.apache.commons.io.test.TestUtils.checkFile; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -30,7 +31,6 @@ import java.io.Writer; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; -import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -171,64 +171,44 @@ public class FileWriterWithEncodingTest { //----------------------------------------------------------------------- @Test public void constructor_File_encoding_badEncoding() { - Writer writer = null; - try { - writer = new FileWriterWithEncoding(file1, "BAD-ENCODE"); - fail(); - } catch (final IOException ex) { - // expected - assertFalse(file1.exists()); - } finally { - IOUtils.closeQuietly(writer); - } + assertThrows(IOException.class, () -> { + try ( + Writer writer = new FileWriterWithEncoding(file1, "BAD-ENCODE"); + ){ } + }); assertFalse(file1.exists()); } //----------------------------------------------------------------------- @Test public void constructor_File_directory() { - Writer writer = null; - try { - writer = new FileWriterWithEncoding(temporaryFolder, defaultEncoding); - fail(); - } catch (final IOException ex) { - // expected - assertFalse(file1.exists()); - } finally { - IOUtils.closeQuietly(writer); - } + assertThrows(IOException.class, () -> { + try ( + Writer writer = new FileWriterWithEncoding(temporaryFolder, defaultEncoding); + ){ } + }); assertFalse(file1.exists()); } //----------------------------------------------------------------------- @Test public void constructor_File_nullFile() throws IOException { - Writer writer = null; - try { - writer = new FileWriterWithEncoding((File) null, defaultEncoding); - fail(); - } catch (final NullPointerException ex) { - // expected - assertFalse(file1.exists()); - } finally { - IOUtils.closeQuietly(writer); - } + assertThrows(NullPointerException.class, () -> { + try ( + Writer writer = new FileWriterWithEncoding((File) null, defaultEncoding); + ){ } + }); assertFalse(file1.exists()); } //----------------------------------------------------------------------- @Test public void constructor_fileName_nullFile() throws IOException { - Writer writer = null; - try { - writer = new FileWriterWithEncoding((String) null, defaultEncoding); - fail(); - } catch (final NullPointerException ex) { - // expected - assertFalse(file1.exists()); - } finally { - IOUtils.closeQuietly(writer); - } + assertThrows(NullPointerException.class, () -> { + try ( + Writer writer = new FileWriterWithEncoding((String) null, defaultEncoding); + ){ } + }); assertFalse(file1.exists()); }