commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject commons-io git commit: Let JUnit handle the exceptions
Date Tue, 02 May 2017 15:19:37 GMT
Repository: commons-io
Updated Branches:
  refs/heads/master c29e08e98 -> 70b9170ca


Let JUnit handle the exceptions

Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/70b9170c
Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/70b9170c
Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/70b9170c

Branch: refs/heads/master
Commit: 70b9170cac5a47f6d55cdced51e94ac9a8fec28a
Parents: c29e08e
Author: Sebb <sebb@apache.org>
Authored: Tue May 2 16:19:33 2017 +0100
Committer: Sebb <sebb@apache.org>
Committed: Tue May 2 16:19:33 2017 +0100

----------------------------------------------------------------------
 .../io/DirectoryWalkerTestCaseJava4.java        |  37 +-
 .../commons/io/input/ProxyReaderTest.java       |  23 +-
 .../commons/io/input/TaggedInputStreamTest.java |  58 +--
 .../monitor/FileAlterationObserverTestCase.java | 427 +++++++++----------
 .../commons/io/output/ProxyWriterTest.java      |  69 +--
 5 files changed, 252 insertions(+), 362 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-io/blob/70b9170c/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java b/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java
index 2502528..7ea5cd4 100644
--- a/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java
+++ b/src/test/java/org/apache/commons/io/DirectoryWalkerTestCaseJava4.java
@@ -271,9 +271,10 @@ public class DirectoryWalkerTestCaseJava4 {
 
     /**
      * Test Cancel
+     * @throws IOException 
      */
     @Test
-    public void testCancel() {
+    public void testCancel() throws IOException {
         String cancelName = null;
 
         // Cancel on a file
@@ -284,8 +285,6 @@ public class DirectoryWalkerTestCaseJava4 {
         } catch (final DirectoryWalker.CancelException cancel) {
             assertEquals("File:  " + cancelName, cancelName, cancel.getFile().getName());
             assertEquals("Depth: " + cancelName, 5, cancel.getDepth());
-        } catch (final IOException ex) {
-            fail("IOException: " + cancelName + " " + ex);
         }
 
         // Cancel on a directory
@@ -296,26 +295,20 @@ public class DirectoryWalkerTestCaseJava4 {
         } catch (final DirectoryWalker.CancelException cancel) {
             assertEquals("File:  " + cancelName, cancelName, cancel.getFile().getName());
             assertEquals("Depth: " + cancelName, 3, cancel.getDepth());
-        } catch (final IOException ex) {
-            fail("IOException: " + cancelName + " " + ex);
         }
 
         // Suppress CancelException (use same file name as preceding test)
-        try {
-            final List results = new TestCancelWalker(cancelName, true).find(javaDir);
-            final File lastFile = (File) results.get(results.size() - 1);
-            assertEquals("Suppress:  " + cancelName, cancelName, lastFile.getName());
-        } catch (final IOException ex) {
-            fail("Suppress threw " + ex);
-        }
-
+        final List results = new TestCancelWalker(cancelName, true).find(javaDir);
+        final File lastFile = (File) results.get(results.size() - 1);
+        assertEquals("Suppress:  " + cancelName, cancelName, lastFile.getName());
     }
 
     /**
      * Test Cancel
+     * @throws IOException 
      */
     @Test
-    public void testMultiThreadCancel() {
+    public void testMultiThreadCancel() throws IOException {
         String cancelName = "DirectoryWalker.java";
         TestMultiThreadCancelWalker walker = new TestMultiThreadCancelWalker(cancelName,
false);
         // Cancel on a file
@@ -326,8 +319,6 @@ public class DirectoryWalkerTestCaseJava4 {
             final File last = (File) walker.results.get(walker.results.size() - 1);
             assertEquals(cancelName, last.getName());
             assertEquals("Depth: " + cancelName, 5, cancel.getDepth());
-        } catch (final IOException ex) {
-            fail("IOException: " + cancelName + " " + ex);
         }
 
         // Cancel on a directory
@@ -339,19 +330,13 @@ public class DirectoryWalkerTestCaseJava4 {
         } catch (final DirectoryWalker.CancelException cancel) {
             assertEquals("File:  " + cancelName, cancelName, cancel.getFile().getName());
             assertEquals("Depth: " + cancelName, 3, cancel.getDepth());
-        } catch (final IOException ex) {
-            fail("IOException: " + cancelName + " " + ex);
         }
 
         // Suppress CancelException (use same file name as preceding test)
-        try {
-            walker = new TestMultiThreadCancelWalker(cancelName, true);
-            final List results = walker.find(javaDir);
-            final File lastFile = (File) results.get(results.size() - 1);
-            assertEquals("Suppress:  " + cancelName, cancelName, lastFile.getName());
-        } catch (final IOException ex) {
-            fail("Suppress threw " + ex);
-        }
+        walker = new TestMultiThreadCancelWalker(cancelName, true);
+        final List results = walker.find(javaDir);
+        final File lastFile = (File) results.get(results.size() - 1);
+        assertEquals("Suppress:  " + cancelName, cancelName, lastFile.getName());
 
     }
 

http://git-wip-us.apache.org/repos/asf/commons-io/blob/70b9170c/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java b/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java
index a6f8ee2..fd1d960 100644
--- a/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/ProxyReaderTest.java
@@ -22,8 +22,6 @@ import java.io.IOException;
 import java.io.Reader;
 import java.nio.CharBuffer;
 
-import static org.junit.Assert.fail;
-
 /**
  * Test {@link ProxyReader}. 
  *
@@ -34,18 +32,8 @@ public class ProxyReaderTest {
     public void testNullCharArray() throws Exception {
 
         final ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0));
-
-        try {
-            proxy.read((char[])null);
-        } catch(final Exception e) {
-            fail("Writing null String threw " + e);
-        }
-
-        try {
-            proxy.read(null, 0, 0);
-        } catch(final Exception e) {
-            fail("Writing null String threw " + e);
-        }
+        proxy.read((char[])null);
+        proxy.read(null, 0, 0);
         proxy.close();
     }
 
@@ -53,12 +41,7 @@ public class ProxyReaderTest {
     public void testNullCharBuffer() throws Exception {
 
         final ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0));
-
-        try {
-            proxy.read((CharBuffer)null);
-        } catch(final Exception e) {
-            fail("Writing null String threw " + e);
-        }
+        proxy.read((CharBuffer)null);
         proxy.close();
     }
 

http://git-wip-us.apache.org/repos/asf/commons-io/blob/70b9170c/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java b/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java
index 8e52285..4bd25fe 100644
--- a/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/TaggedInputStreamTest.java
@@ -35,36 +35,28 @@ import static org.junit.Assert.fail;
 public class TaggedInputStreamTest  {
 
     @Test
-    public void testEmptyStream() {
-        try {
-            final InputStream stream = new TaggedInputStream(new ClosedInputStream());
-            assertEquals(0, stream.available());
-            assertEquals(-1, stream.read());
-            assertEquals(-1, stream.read(new byte[1]));
-            assertEquals(-1, stream.read(new byte[1], 0, 1));
-            stream.close();
-        } catch (final IOException e) {
-            fail("Unexpected exception thrown");
-        }
+    public void testEmptyStream() throws IOException {
+        final InputStream stream = new TaggedInputStream(new ClosedInputStream());
+        assertEquals(0, stream.available());
+        assertEquals(-1, stream.read());
+        assertEquals(-1, stream.read(new byte[1]));
+        assertEquals(-1, stream.read(new byte[1], 0, 1));
+        stream.close();
     }
 
     @Test
-    public void testNormalStream() {
-        try {
-            final InputStream stream = new TaggedInputStream(
-                    new ByteArrayInputStream(new byte[] { 'a', 'b', 'c' }));
-            assertEquals(3, stream.available());
-            assertEquals('a', stream.read());
-            final byte[] buffer = new byte[1];
-            assertEquals(1, stream.read(buffer));
-            assertEquals('b', buffer[0]);
-            assertEquals(1, stream.read(buffer, 0, 1));
-            assertEquals('c', buffer[0]);
-            assertEquals(-1, stream.read());
-            stream.close();
-        } catch (final IOException e) {
-            fail("Unexpected exception thrown");
-        }
+    public void testNormalStream() throws IOException {
+        final InputStream stream = new TaggedInputStream(
+                new ByteArrayInputStream(new byte[] { 'a', 'b', 'c' }));
+        assertEquals(3, stream.available());
+        assertEquals('a', stream.read());
+        final byte[] buffer = new byte[1];
+        assertEquals(1, stream.read(buffer));
+        assertEquals('b', buffer[0]);
+        assertEquals(1, stream.read(buffer, 0, 1));
+        assertEquals('c', buffer[0]);
+        assertEquals(-1, stream.read());
+        stream.close();
     }
 
     @Test
@@ -126,18 +118,10 @@ public class TaggedInputStreamTest  {
         assertFalse(stream.isCauseOf(
                 new TaggedIOException(exception, UUID.randomUUID())));
 
-        try {
-            stream.throwIfCauseOf(exception);
-        } catch (final IOException e) {
-            fail("Unexpected exception thrown");
-        }
+        stream.throwIfCauseOf(exception);
 
-        try {
-            stream.throwIfCauseOf(
+        stream.throwIfCauseOf(
                     new TaggedIOException(exception, UUID.randomUUID()));
-        } catch (final IOException e) {
-            fail("Unexpected exception thrown");
-        }
         stream.close();
     }
 

http://git-wip-us.apache.org/repos/asf/commons-io/blob/70b9170c/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
b/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
index 9564662..5e986a2 100644
--- a/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
+++ b/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
@@ -28,7 +28,6 @@ import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 /**
  * {@link FileAlterationObserver} Test Case.
@@ -149,246 +148,232 @@ public class FileAlterationObserverTestCase extends AbstractMonitorTestCase
{
 
     /**
      * Test checkAndNotify() creating
+     * @throws Exception 
      */
     @Test
-    public void testFileCreate() {
-        try {
-            checkAndNotify();
-            checkCollectionsEmpty("A");
-            File testDirA = new File(testDir, "test-dir-A");
-            testDirA.mkdir();
-            testDir  = touch(testDir);
-            testDirA = touch(testDirA);
-            File testDirAFile1 =       new File(testDirA, "A-file1.java");
-            final File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
-            File testDirAFile3 =       new File(testDirA, "A-file3.java");
-            final File testDirAFile4 = touch(new File(testDirA, "A-file4.java"));
-            File testDirAFile5 =       new File(testDirA, "A-file5.java");
-
-            checkAndNotify();
-            checkCollectionSizes("B", 1, 0, 0, 2, 0, 0);
-            assertFalse("B testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
-            assertTrue("B testDirAFile2",  listener.getCreatedFiles().contains(testDirAFile2));
-            assertFalse("B testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
-            assertTrue("B testDirAFile4",  listener.getCreatedFiles().contains(testDirAFile4));
-            assertFalse("B testDirAFile5", listener.getCreatedFiles().contains(testDirAFile5));
-
-            assertFalse("B testDirAFile1 exists", testDirAFile1.exists());
-            assertTrue("B testDirAFile2 exists",  testDirAFile2.exists());
-            assertFalse("B testDirAFile3 exists", testDirAFile3.exists());
-            assertTrue("B testDirAFile4 exists",  testDirAFile4.exists());
-            assertFalse("B testDirAFile5 exists", testDirAFile5.exists());
-
-            checkAndNotify();
-            checkCollectionsEmpty("C");
-
-            // Create file with name < first entry
-            testDirAFile1 = touch(testDirAFile1);
-            testDirA      = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("D", 0, 1, 0, 1, 0, 0);
-            assertTrue("D testDirAFile1 exists", testDirAFile1.exists());
-            assertTrue("D testDirAFile1",  listener.getCreatedFiles().contains(testDirAFile1));
-
-            // Create file with name between 2 entries
-            testDirAFile3 = touch(testDirAFile3);
-            testDirA      = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("E", 0, 1, 0, 1, 0, 0);
-            assertTrue("E testDirAFile3 exists", testDirAFile3.exists());
-            assertTrue("E testDirAFile3",  listener.getCreatedFiles().contains(testDirAFile3));
-
-            // Create file with name > last entry
-            testDirAFile5 = touch(testDirAFile5);
-            testDirA      = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("F", 0, 1, 0, 1, 0, 0);
-            assertTrue("F testDirAFile5 exists", testDirAFile5.exists());
-            assertTrue("F testDirAFile5",  listener.getCreatedFiles().contains(testDirAFile5));
-        } catch (final Exception e) {
-            fail("Threw " + e);
-        }
+    public void testFileCreate() throws Exception {
+        checkAndNotify();
+        checkCollectionsEmpty("A");
+        File testDirA = new File(testDir, "test-dir-A");
+        testDirA.mkdir();
+        testDir  = touch(testDir);
+        testDirA = touch(testDirA);
+        File testDirAFile1 =       new File(testDirA, "A-file1.java");
+        final File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
+        File testDirAFile3 =       new File(testDirA, "A-file3.java");
+        final File testDirAFile4 = touch(new File(testDirA, "A-file4.java"));
+        File testDirAFile5 =       new File(testDirA, "A-file5.java");
+
+        checkAndNotify();
+        checkCollectionSizes("B", 1, 0, 0, 2, 0, 0);
+        assertFalse("B testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
+        assertTrue("B testDirAFile2",  listener.getCreatedFiles().contains(testDirAFile2));
+        assertFalse("B testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
+        assertTrue("B testDirAFile4",  listener.getCreatedFiles().contains(testDirAFile4));
+        assertFalse("B testDirAFile5", listener.getCreatedFiles().contains(testDirAFile5));
+
+        assertFalse("B testDirAFile1 exists", testDirAFile1.exists());
+        assertTrue("B testDirAFile2 exists",  testDirAFile2.exists());
+        assertFalse("B testDirAFile3 exists", testDirAFile3.exists());
+        assertTrue("B testDirAFile4 exists",  testDirAFile4.exists());
+        assertFalse("B testDirAFile5 exists", testDirAFile5.exists());
+
+        checkAndNotify();
+        checkCollectionsEmpty("C");
+
+        // Create file with name < first entry
+        testDirAFile1 = touch(testDirAFile1);
+        testDirA      = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("D", 0, 1, 0, 1, 0, 0);
+        assertTrue("D testDirAFile1 exists", testDirAFile1.exists());
+        assertTrue("D testDirAFile1",  listener.getCreatedFiles().contains(testDirAFile1));
+
+        // Create file with name between 2 entries
+        testDirAFile3 = touch(testDirAFile3);
+        testDirA      = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("E", 0, 1, 0, 1, 0, 0);
+        assertTrue("E testDirAFile3 exists", testDirAFile3.exists());
+        assertTrue("E testDirAFile3",  listener.getCreatedFiles().contains(testDirAFile3));
+
+        // Create file with name > last entry
+        testDirAFile5 = touch(testDirAFile5);
+        testDirA      = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("F", 0, 1, 0, 1, 0, 0);
+        assertTrue("F testDirAFile5 exists", testDirAFile5.exists());
+        assertTrue("F testDirAFile5",  listener.getCreatedFiles().contains(testDirAFile5));
     }
 
     /**
      * Test checkAndNotify() creating
+     * @throws Exception 
      */
     @Test
-    public void testFileUpdate() {
-        try {
-            checkAndNotify();
-            checkCollectionsEmpty("A");
-            File testDirA = new File(testDir, "test-dir-A");
-            testDirA.mkdir();
-            testDir  = touch(testDir);
-            testDirA = touch(testDirA);
-            File testDirAFile1 = touch(new File(testDirA, "A-file1.java"));
-            final File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
-            File testDirAFile3 = touch(new File(testDirA, "A-file3.java"));
-            final File testDirAFile4 = touch(new File(testDirA, "A-file4.java"));
-            File testDirAFile5 = touch(new File(testDirA, "A-file5.java"));
-
-            checkAndNotify();
-            checkCollectionSizes("B", 1, 0, 0, 5, 0, 0);
-            assertTrue("B testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
-            assertTrue("B testDirAFile2", listener.getCreatedFiles().contains(testDirAFile2));
-            assertTrue("B testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
-            assertTrue("B testDirAFile4", listener.getCreatedFiles().contains(testDirAFile4));
-            assertTrue("B testDirAFile5", listener.getCreatedFiles().contains(testDirAFile5));
-
-            assertTrue("B testDirAFile1 exists", testDirAFile1.exists());
-            assertTrue("B testDirAFile2 exists", testDirAFile2.exists());
-            assertTrue("B testDirAFile3 exists", testDirAFile3.exists());
-            assertTrue("B testDirAFile4 exists", testDirAFile4.exists());
-            assertTrue("B testDirAFile5 exists", testDirAFile5.exists());
-
-            checkAndNotify();
-            checkCollectionsEmpty("C");
-
-            // Update first entry
-            testDirAFile1 = touch(testDirAFile1);
-            testDirA      = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("D", 0, 1, 0, 0, 1, 0);
-            assertTrue("D testDirAFile1",  listener.getChangedFiles().contains(testDirAFile1));
-
-            // Update file with name between 2 entries
-            testDirAFile3 = touch(testDirAFile3);
-            testDirA      = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("E", 0, 1, 0, 0, 1, 0);
-            assertTrue("E testDirAFile3",  listener.getChangedFiles().contains(testDirAFile3));
-
-            // Update last entry
-            testDirAFile5 = touch(testDirAFile5);
-            testDirA      = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("F", 0, 1, 0, 0, 1, 0);
-            assertTrue("F testDirAFile5",  listener.getChangedFiles().contains(testDirAFile5));
-        } catch (final Exception e) {
-            fail("Threw " + e);
-        }
+    public void testFileUpdate() throws Exception {
+        checkAndNotify();
+        checkCollectionsEmpty("A");
+        File testDirA = new File(testDir, "test-dir-A");
+        testDirA.mkdir();
+        testDir  = touch(testDir);
+        testDirA = touch(testDirA);
+        File testDirAFile1 = touch(new File(testDirA, "A-file1.java"));
+        final File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
+        File testDirAFile3 = touch(new File(testDirA, "A-file3.java"));
+        final File testDirAFile4 = touch(new File(testDirA, "A-file4.java"));
+        File testDirAFile5 = touch(new File(testDirA, "A-file5.java"));
+
+        checkAndNotify();
+        checkCollectionSizes("B", 1, 0, 0, 5, 0, 0);
+        assertTrue("B testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
+        assertTrue("B testDirAFile2", listener.getCreatedFiles().contains(testDirAFile2));
+        assertTrue("B testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
+        assertTrue("B testDirAFile4", listener.getCreatedFiles().contains(testDirAFile4));
+        assertTrue("B testDirAFile5", listener.getCreatedFiles().contains(testDirAFile5));
+
+        assertTrue("B testDirAFile1 exists", testDirAFile1.exists());
+        assertTrue("B testDirAFile2 exists", testDirAFile2.exists());
+        assertTrue("B testDirAFile3 exists", testDirAFile3.exists());
+        assertTrue("B testDirAFile4 exists", testDirAFile4.exists());
+        assertTrue("B testDirAFile5 exists", testDirAFile5.exists());
+
+        checkAndNotify();
+        checkCollectionsEmpty("C");
+
+        // Update first entry
+        testDirAFile1 = touch(testDirAFile1);
+        testDirA      = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("D", 0, 1, 0, 0, 1, 0);
+        assertTrue("D testDirAFile1",  listener.getChangedFiles().contains(testDirAFile1));
+
+        // Update file with name between 2 entries
+        testDirAFile3 = touch(testDirAFile3);
+        testDirA      = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("E", 0, 1, 0, 0, 1, 0);
+        assertTrue("E testDirAFile3",  listener.getChangedFiles().contains(testDirAFile3));
+
+        // Update last entry
+        testDirAFile5 = touch(testDirAFile5);
+        testDirA      = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("F", 0, 1, 0, 0, 1, 0);
+        assertTrue("F testDirAFile5",  listener.getChangedFiles().contains(testDirAFile5));
     }
 
     /**
      * Test checkAndNotify() deleting
+     * @throws Exception 
      */
     @Test
-    public void testFileDelete() {
-        try {
-            checkAndNotify();
-            checkCollectionsEmpty("A");
-            File testDirA = new File(testDir, "test-dir-A");
-            testDirA.mkdir();
-            testDir  = touch(testDir);
-            testDirA = touch(testDirA);
-            final File testDirAFile1 = touch(new File(testDirA, "A-file1.java"));
-            final File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
-            final File testDirAFile3 = touch(new File(testDirA, "A-file3.java"));
-            final File testDirAFile4 = touch(new File(testDirA, "A-file4.java"));
-            final File testDirAFile5 = touch(new File(testDirA, "A-file5.java"));
-
-            assertTrue("B testDirAFile1 exists", testDirAFile1.exists());
-            assertTrue("B testDirAFile2 exists", testDirAFile2.exists());
-            assertTrue("B testDirAFile3 exists", testDirAFile3.exists());
-            assertTrue("B testDirAFile4 exists", testDirAFile4.exists());
-            assertTrue("B testDirAFile5 exists", testDirAFile5.exists());
-
-            checkAndNotify();
-            checkCollectionSizes("B", 1, 0, 0, 5, 0, 0);
-            assertTrue("B testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
-            assertTrue("B testDirAFile2", listener.getCreatedFiles().contains(testDirAFile2));
-            assertTrue("B testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
-            assertTrue("B testDirAFile4", listener.getCreatedFiles().contains(testDirAFile4));
-            assertTrue("B testDirAFile5", listener.getCreatedFiles().contains(testDirAFile5));
-
-            checkAndNotify();
-            checkCollectionsEmpty("C");
-
-            // Delete first entry
-            FileUtils.deleteQuietly(testDirAFile1);
-            testDirA = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("D", 0, 1, 0, 0, 0, 1);
-            assertFalse("D testDirAFile1 exists", testDirAFile1.exists());
-            assertTrue("D testDirAFile1",  listener.getDeletedFiles().contains(testDirAFile1));
-
-            // Delete file with name between 2 entries
-            FileUtils.deleteQuietly(testDirAFile3);
-            testDirA = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("E", 0, 1, 0, 0, 0, 1);
-            assertFalse("E testDirAFile3 exists", testDirAFile3.exists());
-            assertTrue("E testDirAFile3",  listener.getDeletedFiles().contains(testDirAFile3));
-
-            // Delete last entry
-            FileUtils.deleteQuietly(testDirAFile5);
-            testDirA = touch(testDirA);
-            checkAndNotify();
-            checkCollectionSizes("F", 0, 1, 0, 0, 0, 1);
-            assertFalse("F testDirAFile5 exists", testDirAFile5.exists());
-            assertTrue("F testDirAFile5",  listener.getDeletedFiles().contains(testDirAFile5));
-
-        } catch (final Exception e) {
-            fail("Threw " + e);
-        }
+    public void testFileDelete() throws Exception {
+        checkAndNotify();
+        checkCollectionsEmpty("A");
+        File testDirA = new File(testDir, "test-dir-A");
+        testDirA.mkdir();
+        testDir  = touch(testDir);
+        testDirA = touch(testDirA);
+        final File testDirAFile1 = touch(new File(testDirA, "A-file1.java"));
+        final File testDirAFile2 = touch(new File(testDirA, "A-file2.java"));
+        final File testDirAFile3 = touch(new File(testDirA, "A-file3.java"));
+        final File testDirAFile4 = touch(new File(testDirA, "A-file4.java"));
+        final File testDirAFile5 = touch(new File(testDirA, "A-file5.java"));
+
+        assertTrue("B testDirAFile1 exists", testDirAFile1.exists());
+        assertTrue("B testDirAFile2 exists", testDirAFile2.exists());
+        assertTrue("B testDirAFile3 exists", testDirAFile3.exists());
+        assertTrue("B testDirAFile4 exists", testDirAFile4.exists());
+        assertTrue("B testDirAFile5 exists", testDirAFile5.exists());
+
+        checkAndNotify();
+        checkCollectionSizes("B", 1, 0, 0, 5, 0, 0);
+        assertTrue("B testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
+        assertTrue("B testDirAFile2", listener.getCreatedFiles().contains(testDirAFile2));
+        assertTrue("B testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
+        assertTrue("B testDirAFile4", listener.getCreatedFiles().contains(testDirAFile4));
+        assertTrue("B testDirAFile5", listener.getCreatedFiles().contains(testDirAFile5));
+
+        checkAndNotify();
+        checkCollectionsEmpty("C");
+
+        // Delete first entry
+        FileUtils.deleteQuietly(testDirAFile1);
+        testDirA = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("D", 0, 1, 0, 0, 0, 1);
+        assertFalse("D testDirAFile1 exists", testDirAFile1.exists());
+        assertTrue("D testDirAFile1",  listener.getDeletedFiles().contains(testDirAFile1));
+
+        // Delete file with name between 2 entries
+        FileUtils.deleteQuietly(testDirAFile3);
+        testDirA = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("E", 0, 1, 0, 0, 0, 1);
+        assertFalse("E testDirAFile3 exists", testDirAFile3.exists());
+        assertTrue("E testDirAFile3",  listener.getDeletedFiles().contains(testDirAFile3));
+
+        // Delete last entry
+        FileUtils.deleteQuietly(testDirAFile5);
+        testDirA = touch(testDirA);
+        checkAndNotify();
+        checkCollectionSizes("F", 0, 1, 0, 0, 0, 1);
+        assertFalse("F testDirAFile5 exists", testDirAFile5.exists());
+        assertTrue("F testDirAFile5",  listener.getDeletedFiles().contains(testDirAFile5));
     }
 
     /**
      * Test checkAndNotify() method
+     * @throws Exception
      */
     @Test
-    public void testObserveSingleFile() {
-        try {
-            final File testDirA = new File(testDir, "test-dir-A");
-            File testDirAFile1 = new File(testDirA, "A-file1.java");
-            testDirA.mkdir();
-
-            final FileFilter nameFilter = FileFilterUtils.nameFileFilter(testDirAFile1.getName());
-            createObserver(testDirA, nameFilter);
-            checkAndNotify();
-            checkCollectionsEmpty("A");
-            assertFalse("A testDirAFile1 exists", testDirAFile1.exists());
-
-            // Create
-            testDirAFile1 = touch(testDirAFile1);
-            File testDirAFile2 = touch(new File(testDirA, "A-file2.txt"));  /* filter should
ignore */
-            File testDirAFile3 = touch(new File(testDirA, "A-file3.java")); /* filter should
ignore */
-            assertTrue("B testDirAFile1 exists", testDirAFile1.exists());
-            assertTrue("B testDirAFile2 exists", testDirAFile2.exists());
-            assertTrue("B testDirAFile3 exists", testDirAFile3.exists());
-            checkAndNotify();
-            checkCollectionSizes("C", 0, 0, 0, 1, 0, 0);
-            assertTrue("C created", listener.getCreatedFiles().contains(testDirAFile1));
-            assertFalse("C created", listener.getCreatedFiles().contains(testDirAFile2));
-            assertFalse("C created", listener.getCreatedFiles().contains(testDirAFile3));
-
-            // Modify
-            testDirAFile1 = touch(testDirAFile1);
-            testDirAFile2 = touch(testDirAFile2);
-            testDirAFile3 = touch(testDirAFile3);
-            checkAndNotify();
-            checkCollectionSizes("D", 0, 0, 0, 0, 1, 0);
-            assertTrue("D changed", listener.getChangedFiles().contains(testDirAFile1));
-            assertFalse("D changed", listener.getChangedFiles().contains(testDirAFile2));
-            assertFalse("D changed", listener.getChangedFiles().contains(testDirAFile3));
-
-            // Delete
-            FileUtils.deleteQuietly(testDirAFile1);
-            FileUtils.deleteQuietly(testDirAFile2);
-            FileUtils.deleteQuietly(testDirAFile3);
-            assertFalse("E testDirAFile1 exists", testDirAFile1.exists());
-            assertFalse("E testDirAFile2 exists", testDirAFile2.exists());
-            assertFalse("E testDirAFile3 exists", testDirAFile3.exists());
-            checkAndNotify();
-            checkCollectionSizes("E", 0, 0, 0, 0, 0, 1);
-            assertTrue("E deleted", listener.getDeletedFiles().contains(testDirAFile1));
-            assertFalse("E deleted", listener.getDeletedFiles().contains(testDirAFile2));
-            assertFalse("E deleted", listener.getDeletedFiles().contains(testDirAFile3));
-
-        } catch (final Exception e) {
-            fail("Threw " + e);
-        }
+    public void testObserveSingleFile() throws Exception {
+        final File testDirA = new File(testDir, "test-dir-A");
+        File testDirAFile1 = new File(testDirA, "A-file1.java");
+        testDirA.mkdir();
+
+        final FileFilter nameFilter = FileFilterUtils.nameFileFilter(testDirAFile1.getName());
+        createObserver(testDirA, nameFilter);
+        checkAndNotify();
+        checkCollectionsEmpty("A");
+        assertFalse("A testDirAFile1 exists", testDirAFile1.exists());
+
+        // Create
+        testDirAFile1 = touch(testDirAFile1);
+        File testDirAFile2 = touch(new File(testDirA, "A-file2.txt"));  /* filter should
ignore */
+        File testDirAFile3 = touch(new File(testDirA, "A-file3.java")); /* filter should
ignore */
+        assertTrue("B testDirAFile1 exists", testDirAFile1.exists());
+        assertTrue("B testDirAFile2 exists", testDirAFile2.exists());
+        assertTrue("B testDirAFile3 exists", testDirAFile3.exists());
+        checkAndNotify();
+        checkCollectionSizes("C", 0, 0, 0, 1, 0, 0);
+        assertTrue("C created", listener.getCreatedFiles().contains(testDirAFile1));
+        assertFalse("C created", listener.getCreatedFiles().contains(testDirAFile2));
+        assertFalse("C created", listener.getCreatedFiles().contains(testDirAFile3));
+
+        // Modify
+        testDirAFile1 = touch(testDirAFile1);
+        testDirAFile2 = touch(testDirAFile2);
+        testDirAFile3 = touch(testDirAFile3);
+        checkAndNotify();
+        checkCollectionSizes("D", 0, 0, 0, 0, 1, 0);
+        assertTrue("D changed", listener.getChangedFiles().contains(testDirAFile1));
+        assertFalse("D changed", listener.getChangedFiles().contains(testDirAFile2));
+        assertFalse("D changed", listener.getChangedFiles().contains(testDirAFile3));
+
+        // Delete
+        FileUtils.deleteQuietly(testDirAFile1);
+        FileUtils.deleteQuietly(testDirAFile2);
+        FileUtils.deleteQuietly(testDirAFile3);
+        assertFalse("E testDirAFile1 exists", testDirAFile1.exists());
+        assertFalse("E testDirAFile2 exists", testDirAFile2.exists());
+        assertFalse("E testDirAFile3 exists", testDirAFile3.exists());
+        checkAndNotify();
+        checkCollectionSizes("E", 0, 0, 0, 0, 0, 1);
+        assertTrue("E deleted", listener.getDeletedFiles().contains(testDirAFile1));
+        assertFalse("E deleted", listener.getDeletedFiles().contains(testDirAFile2));
+        assertFalse("E deleted", listener.getDeletedFiles().contains(testDirAFile3));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-io/blob/70b9170c/src/test/java/org/apache/commons/io/output/ProxyWriterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/output/ProxyWriterTest.java b/src/test/java/org/apache/commons/io/output/ProxyWriterTest.java
index 93fd068..40bf88f 100644
--- a/src/test/java/org/apache/commons/io/output/ProxyWriterTest.java
+++ b/src/test/java/org/apache/commons/io/output/ProxyWriterTest.java
@@ -17,8 +17,6 @@
 package org.apache.commons.io.output;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
@@ -36,11 +34,7 @@ public class ProxyWriterTest {
     public void appendCharSequence() throws Exception {
         final StringBuilderWriter writer = new StringBuilderWriter();
         final ProxyWriter proxy = new ProxyWriter(writer);
-        try {
-            proxy.append("ABC");
-        } catch (final Exception e) {
-            fail("Appending CharSequence threw " + e);
-        }
+        proxy.append("ABC");
         assertEquals("ABC", writer.toString());
         proxy.close();
     }
@@ -68,11 +62,7 @@ public class ProxyWriterTest {
     public void writeString() throws Exception {
         final StringBuilderWriter writer = new StringBuilderWriter();
         final ProxyWriter proxy = new ProxyWriter(writer);
-        try {
-            proxy.write("ABC");
-        } catch (final Exception e) {
-            fail("Writing String threw " + e);
-        }
+        proxy.write("ABC");
         assertEquals("ABC", writer.toString());
         proxy.close();
     }
@@ -81,11 +71,7 @@ public class ProxyWriterTest {
     public void writeStringPartial() throws Exception {
         final StringBuilderWriter writer = new StringBuilderWriter();
         final ProxyWriter proxy = new ProxyWriter(writer);
-        try {
-            proxy.write("ABC", 1, 2);
-        } catch (final Exception e) {
-            fail("Writing String threw " + e);
-        }
+        proxy.write("ABC", 1, 2);
         assertEquals("BC", writer.toString());
         proxy.close();
     }
@@ -94,11 +80,7 @@ public class ProxyWriterTest {
     public void writeCharArray() throws Exception {
         final StringBuilderWriter writer = new StringBuilderWriter();
         final ProxyWriter proxy = new ProxyWriter(writer);
-        try {
-            proxy.write(new char[]{'A', 'B', 'C'});
-        } catch (final Exception e) {
-            fail("Writing char[] threw " + e);
-        }
+        proxy.write(new char[]{'A', 'B', 'C'});
         assertEquals("ABC", writer.toString());
         proxy.close();
     }
@@ -107,11 +89,7 @@ public class ProxyWriterTest {
     public void writeInt() throws Exception {
         final StringBuilderWriter writer = new StringBuilderWriter();
         final ProxyWriter proxy = new ProxyWriter(writer);
-        try {
-            proxy.write(65);
-        } catch (final Exception e) {
-            fail("Writing char[] threw " + e);
-        }
+        proxy.write(65);
         assertEquals("A", writer.toString());
         proxy.close();
     }
@@ -120,11 +98,7 @@ public class ProxyWriterTest {
     public void writeCharArrayPartial() throws Exception {
         final StringBuilderWriter writer = new StringBuilderWriter();
         final ProxyWriter proxy = new ProxyWriter(writer);
-        try {
-            proxy.write(new char[]{'A', 'B', 'C'}, 1, 2);
-        } catch (final Exception e) {
-            fail("Writing char[] threw " + e);
-        }
+        proxy.write(new char[]{'A', 'B', 'C'}, 1, 2);
         assertEquals("BC", writer.toString());
         proxy.close();
     }
@@ -134,17 +108,8 @@ public class ProxyWriterTest {
 
         final ProxyWriter proxy = new ProxyWriter(new NullWriter());
 
-        try {
-            proxy.write((String) null);
-        } catch (final Exception e) {
-            fail("Writing null String threw " + e);
-        }
-
-        try {
-            proxy.write((String) null, 0, 0);
-        } catch (final Exception e) {
-            fail("Writing null String threw " + e);
-        }
+        proxy.write((String) null);
+        proxy.write((String) null, 0, 0);
         proxy.close();
     }
 
@@ -153,17 +118,9 @@ public class ProxyWriterTest {
 
         final ProxyWriter proxy = new ProxyWriter(new NullWriter());
 
-        try {
-            proxy.write((char[]) null);
-        } catch (final Exception e) {
-            fail("Writing null char[] threw " + e);
-        }
+        proxy.write((char[]) null);
 
-        try {
-            proxy.write((char[]) null, 0, 0);
-        } catch (final Exception e) {
-            fail("Writing null char[] threw " + e);
-        }
+        proxy.write((char[]) null, 0, 0);
         proxy.close();
     }
 
@@ -172,11 +129,7 @@ public class ProxyWriterTest {
 
         final ProxyWriter proxy = new ProxyWriter(new NullWriter());
 
-        try {
-            proxy.append(null);
-        } catch (final Exception e) {
-            fail("Appending null CharSequence threw " + e);
-        }
+        proxy.append(null);
         proxy.close();
     }
 


Mime
View raw message