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 10:33:18 GMT
Repository: commons-io
Updated Branches:
  refs/heads/master f00d97a6c -> c29e08e98


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/c29e08e9
Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/c29e08e9
Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/c29e08e9

Branch: refs/heads/master
Commit: c29e08e98a4d1f12842375cb8fb259b8e5054b0f
Parents: f00d97a
Author: Sebb <sebb@apache.org>
Authored: Tue May 2 11:33:15 2017 +0100
Committer: Sebb <sebb@apache.org>
Committed: Tue May 2 11:33:15 2017 +0100

----------------------------------------------------------------------
 .../monitor/FileAlterationMonitorTestCase.java  | 133 +++++++++----------
 .../monitor/FileAlterationObserverTestCase.java | 110 ++++++++-------
 2 files changed, 115 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-io/blob/c29e08e9/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
b/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
index 973b150..0a3fa34 100644
--- a/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
+++ b/src/test/java/org/apache/commons/io/monitor/FileAlterationMonitorTestCase.java
@@ -90,88 +90,79 @@ public class FileAlterationMonitorTestCase extends AbstractMonitorTestCase
{
 
     /**
      * Test checkAndNotify() method
+     * @throws Exception 
      */
     @Test
-    public void testMonitor() {
+    public void testMonitor() throws Exception {
+        final long interval = 100;
+        listener.clear();
+        final FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer);
+        assertEquals("Interval", interval, monitor.getInterval());
+        monitor.start();
+
         try {
-            final long interval = 100;
-            listener.clear();
-            final FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer);
-            assertEquals("Interval", interval, monitor.getInterval());
-            monitor.start();
-
-            try {
-                monitor.start(); // try and start again
-                fail("Expected IllegalStateException");
-            } catch (final IllegalStateException e) {
-                // expected result, monitor already running
-            }
+            monitor.start(); // try and start again
+            fail("Expected IllegalStateException");
+        } catch (final IllegalStateException e) {
+            // expected result, monitor already running
+        }
 
-            // Create a File
-            checkCollectionsEmpty("A");
-            File file1 = touch(new File(testDir, "file1.java"));
-            checkFile("Create", file1, listener.getCreatedFiles());
-            listener.clear();
-
-            // Update a file
-            checkCollectionsEmpty("B");
-            file1 = touch(file1);
-            checkFile("Update", file1, listener.getChangedFiles());
-            listener.clear();
-
-            // Delete a file
-            checkCollectionsEmpty("C");
-            file1.delete();
-            checkFile("Delete", file1, listener.getDeletedFiles());
-            listener.clear();
-
-            // Stop monitoring
-            monitor.stop();
-
-            try {
-                monitor.stop(); // try and stop again
-                fail("Expected IllegalStateException");
-            } catch (final IllegalStateException e) {
-                // expected result, monitor already stopped
-            }
-        } catch (final Exception e) {
-            e.printStackTrace();
-            fail("Threw " + e);
+        // Create a File
+        checkCollectionsEmpty("A");
+        File file1 = touch(new File(testDir, "file1.java"));
+        checkFile("Create", file1, listener.getCreatedFiles());
+        listener.clear();
+
+        // Update a file
+        checkCollectionsEmpty("B");
+        file1 = touch(file1);
+        checkFile("Update", file1, listener.getChangedFiles());
+        listener.clear();
+
+        // Delete a file
+        checkCollectionsEmpty("C");
+        file1.delete();
+        checkFile("Delete", file1, listener.getDeletedFiles());
+        listener.clear();
+
+        // Stop monitoring
+        monitor.stop();
+
+        try {
+            monitor.stop(); // try and stop again
+            fail("Expected IllegalStateException");
+        } catch (final IllegalStateException e) {
+            // expected result, monitor already stopped
         }
     }
 
     /**
      * Test using a thread factory.
+     * @throws Exception 
      */
     @Test
-    public void testThreadFactory() {
-        try {
-            final long interval = 100;
-            listener.clear();
-            final FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer);
-            monitor.setThreadFactory(Executors.defaultThreadFactory());
-            assertEquals("Interval", interval, monitor.getInterval());
-            monitor.start();
-
-            // Create a File
-            checkCollectionsEmpty("A");
-            final File file2 = touch(new File(testDir, "file2.java"));
-            checkFile("Create", file2, listener.getCreatedFiles());
-            listener.clear();
-
-            // Delete a file
-            checkCollectionsEmpty("B");
-            file2.delete();
-            checkFile("Delete", file2, listener.getDeletedFiles());
-            listener.clear();
-
-            // Stop monitoring
-            monitor.stop();
-
-        } catch (final Exception e) {
-            e.printStackTrace();
-            fail("Threw " + e);
-        }
+    public void testThreadFactory() throws Exception {
+        final long interval = 100;
+        listener.clear();
+        final FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer);
+        monitor.setThreadFactory(Executors.defaultThreadFactory());
+        assertEquals("Interval", interval, monitor.getInterval());
+        monitor.start();
+
+        // Create a File
+        checkCollectionsEmpty("A");
+        final File file2 = touch(new File(testDir, "file2.java"));
+        checkFile("Create", file2, listener.getCreatedFiles());
+        listener.clear();
+
+        // Delete a file
+        checkCollectionsEmpty("B");
+        file2.delete();
+        checkFile("Delete", file2, listener.getDeletedFiles());
+        listener.clear();
+
+        // Stop monitoring
+        monitor.stop();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-io/blob/c29e08e9/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 13758dc..9564662 100644
--- a/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
+++ b/src/test/java/org/apache/commons/io/monitor/FileAlterationObserverTestCase.java
@@ -90,65 +90,61 @@ public class FileAlterationObserverTestCase extends AbstractMonitorTestCase
{
 
     /**
      * Test checkAndNotify() method
+     * @throws Exception 
      */
     @Test
-    public void testDirectory() {
-        try {
-            checkAndNotify();
-            checkCollectionsEmpty("A");
-            final File testDirA = new File(testDir, "test-dir-A");
-            final File testDirB = new File(testDir, "test-dir-B");
-            final File testDirC = new File(testDir, "test-dir-C");
-            testDirA.mkdir();
-            testDirB.mkdir();
-            testDirC.mkdir();
-            final File testDirAFile1 = touch(new File(testDirA, "A-file1.java"));
-            final File testDirAFile2 = touch(new File(testDirA, "A-file2.txt")); // filter
should ignore this
-            final File testDirAFile3 = touch(new File(testDirA, "A-file3.java"));
-            File testDirAFile4 = touch(new File(testDirA, "A-file4.java"));
-            final File testDirBFile1 = touch(new File(testDirB, "B-file1.java"));
-
-            checkAndNotify();
-            checkCollectionSizes("B", 3, 0, 0, 4, 0, 0);
-            assertTrue("B testDirA",   listener.getCreatedDirectories().contains(testDirA));
-            assertTrue("B testDirB",   listener.getCreatedDirectories().contains(testDirB));
-            assertTrue("B testDirC",   listener.getCreatedDirectories().contains(testDirC));
-            assertTrue("B testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
-            assertFalse("B testDirAFile2", listener.getCreatedFiles().contains(testDirAFile2));
-            assertTrue("B testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
-            assertTrue("B testDirAFile4", listener.getCreatedFiles().contains(testDirAFile4));
-            assertTrue("B testDirBFile1", listener.getCreatedFiles().contains(testDirBFile1));
-
-            checkAndNotify();
-            checkCollectionsEmpty("C");
-
-            testDirAFile4 = touch(testDirAFile4);
-            FileUtils.deleteDirectory(testDirB);
-            checkAndNotify();
-            checkCollectionSizes("D", 0, 0, 1, 0, 1, 1);
-            assertTrue("D testDirB",   listener.getDeletedDirectories().contains(testDirB));
-            assertTrue("D testDirAFile4", listener.getChangedFiles().contains(testDirAFile4));
-            assertTrue("D testDirBFile1", listener.getDeletedFiles().contains(testDirBFile1));
-
-            FileUtils.deleteDirectory(testDir);
-            checkAndNotify();
-            checkCollectionSizes("E", 0, 0, 2, 0, 0, 3);
-            assertTrue("E testDirA",   listener.getDeletedDirectories().contains(testDirA));
-            assertTrue("E testDirAFile1", listener.getDeletedFiles().contains(testDirAFile1));
-            assertFalse("E testDirAFile2", listener.getDeletedFiles().contains(testDirAFile2));
-            assertTrue("E testDirAFile3", listener.getDeletedFiles().contains(testDirAFile3));
-            assertTrue("E testDirAFile4", listener.getDeletedFiles().contains(testDirAFile4));
-
-            testDir.mkdir();
-            checkAndNotify();
-            checkCollectionsEmpty("F");
-
-            checkAndNotify();
-            checkCollectionsEmpty("G");
-        } catch (final Exception e) {
-            e.printStackTrace();
-            fail("Threw " + e);
-        }
+    public void testDirectory() throws Exception {
+        checkAndNotify();
+        checkCollectionsEmpty("A");
+        final File testDirA = new File(testDir, "test-dir-A");
+        final File testDirB = new File(testDir, "test-dir-B");
+        final File testDirC = new File(testDir, "test-dir-C");
+        testDirA.mkdir();
+        testDirB.mkdir();
+        testDirC.mkdir();
+        final File testDirAFile1 = touch(new File(testDirA, "A-file1.java"));
+        final File testDirAFile2 = touch(new File(testDirA, "A-file2.txt")); // filter should
ignore this
+        final File testDirAFile3 = touch(new File(testDirA, "A-file3.java"));
+        File testDirAFile4 = touch(new File(testDirA, "A-file4.java"));
+        final File testDirBFile1 = touch(new File(testDirB, "B-file1.java"));
+
+        checkAndNotify();
+        checkCollectionSizes("B", 3, 0, 0, 4, 0, 0);
+        assertTrue("B testDirA",   listener.getCreatedDirectories().contains(testDirA));
+        assertTrue("B testDirB",   listener.getCreatedDirectories().contains(testDirB));
+        assertTrue("B testDirC",   listener.getCreatedDirectories().contains(testDirC));
+        assertTrue("B testDirAFile1", listener.getCreatedFiles().contains(testDirAFile1));
+        assertFalse("B testDirAFile2", listener.getCreatedFiles().contains(testDirAFile2));
+        assertTrue("B testDirAFile3", listener.getCreatedFiles().contains(testDirAFile3));
+        assertTrue("B testDirAFile4", listener.getCreatedFiles().contains(testDirAFile4));
+        assertTrue("B testDirBFile1", listener.getCreatedFiles().contains(testDirBFile1));
+
+        checkAndNotify();
+        checkCollectionsEmpty("C");
+
+        testDirAFile4 = touch(testDirAFile4);
+        FileUtils.deleteDirectory(testDirB);
+        checkAndNotify();
+        checkCollectionSizes("D", 0, 0, 1, 0, 1, 1);
+        assertTrue("D testDirB",   listener.getDeletedDirectories().contains(testDirB));
+        assertTrue("D testDirAFile4", listener.getChangedFiles().contains(testDirAFile4));
+        assertTrue("D testDirBFile1", listener.getDeletedFiles().contains(testDirBFile1));
+
+        FileUtils.deleteDirectory(testDir);
+        checkAndNotify();
+        checkCollectionSizes("E", 0, 0, 2, 0, 0, 3);
+        assertTrue("E testDirA",   listener.getDeletedDirectories().contains(testDirA));
+        assertTrue("E testDirAFile1", listener.getDeletedFiles().contains(testDirAFile1));
+        assertFalse("E testDirAFile2", listener.getDeletedFiles().contains(testDirAFile2));
+        assertTrue("E testDirAFile3", listener.getDeletedFiles().contains(testDirAFile3));
+        assertTrue("E testDirAFile4", listener.getDeletedFiles().contains(testDirAFile4));
+
+        testDir.mkdir();
+        checkAndNotify();
+        checkCollectionsEmpty("F");
+
+        checkAndNotify();
+        checkCollectionsEmpty("G");
     }
 
     /**


Mime
View raw message