jdk/test/java/nio/file/WatchService/Basic.java
changeset 24265 9fc484c7e900
parent 24264 694a3890cbb7
equal deleted inserted replaced
24264:694a3890cbb7 24265:9fc484c7e900
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /* @test
    24 /* @test
    25  * @bug 4313887 6838333 7017446 8011537
    25  * @bug 4313887 6838333 7017446 8011537 8042470
    26  * @summary Unit test for java.nio.file.WatchService
    26  * @summary Unit test for java.nio.file.WatchService
    27  * @library ..
    27  * @library ..
    28  * @run main Basic
    28  * @run main Basic
    29  */
    29  */
    30 
    30 
   293             }
   293             }
   294 
   294 
   295             // IllegalArgumentException
   295             // IllegalArgumentException
   296             System.out.println("IllegalArgumentException tests...");
   296             System.out.println("IllegalArgumentException tests...");
   297             try {
   297             try {
   298                 dir.register(watcher, new WatchEvent.Kind<?>[]{ } );
   298                 dir.register(watcher /*empty event list*/);
   299                 throw new RuntimeException("IllegalArgumentException not thrown");
   299                 throw new RuntimeException("IllegalArgumentException not thrown");
   300             } catch (IllegalArgumentException x) {
   300             } catch (IllegalArgumentException x) {
   301             }
   301             }
   302             try {
   302             try {
   303                 // OVERFLOW is ignored so this is equivalent to the empty set
   303                 // OVERFLOW is ignored so this is equivalent to the empty set
   304                 dir.register(watcher, new WatchEvent.Kind<?>[]{ OVERFLOW });
   304                 dir.register(watcher, OVERFLOW);
   305                 throw new RuntimeException("IllegalArgumentException not thrown");
   305                 throw new RuntimeException("IllegalArgumentException not thrown");
   306             } catch (IllegalArgumentException x) {
   306             } catch (IllegalArgumentException x) {
   307             }
   307             }
       
   308             try {
       
   309                 // OVERFLOW is ignored even if specified multiple times
       
   310                 dir.register(watcher, OVERFLOW, OVERFLOW);
       
   311                 throw new RuntimeException("IllegalArgumentException not thrown");
       
   312             } catch (IllegalArgumentException x) {
       
   313             }
   308 
   314 
   309             // UnsupportedOperationException
   315             // UnsupportedOperationException
   310             try {
   316             try {
   311                 dir.register(watcher, new WatchEvent.Kind<?>[]{
   317                 dir.register(watcher,
   312                              new WatchEvent.Kind<Object>() {
   318                              new WatchEvent.Kind<Object>() {
   313                                 @Override public String name() { return "custom"; }
   319                                 @Override public String name() { return "custom"; }
   314                                 @Override public Class<Object> type() { return Object.class; }
   320                                 @Override public Class<Object> type() { return Object.class; }
   315                              }});
   321                              });
       
   322                 throw new RuntimeException("UnsupportedOperationException not thrown");
   316             } catch (UnsupportedOperationException x) {
   323             } catch (UnsupportedOperationException x) {
   317             }
   324             }
   318             try {
   325             try {
   319                 dir.register(watcher,
   326                 dir.register(watcher,
   320                              new WatchEvent.Kind<?>[]{ ENTRY_CREATE },
   327                              new WatchEvent.Kind<?>[]{ ENTRY_CREATE },
   326             }
   333             }
   327 
   334 
   328             // NullPointerException
   335             // NullPointerException
   329             System.out.println("NullPointerException tests...");
   336             System.out.println("NullPointerException tests...");
   330             try {
   337             try {
   331                 dir.register(null, new WatchEvent.Kind<?>[]{ ENTRY_CREATE });
   338                 dir.register(null, ENTRY_CREATE);
   332                 throw new RuntimeException("NullPointerException not thrown");
   339                 throw new RuntimeException("NullPointerException not thrown");
   333             } catch (NullPointerException x) {
   340             } catch (NullPointerException x) {
   334             }
   341             }
   335             try {
   342             try {
   336                 dir.register(watcher, new WatchEvent.Kind<?>[]{ null });
   343                 dir.register(watcher, new WatchEvent.Kind<?>[]{ null });
   378         } catch (ClosedWatchServiceException  x) {
   385         } catch (ClosedWatchServiceException  x) {
   379         }
   386         }
   380 
   387 
   381         try {
   388         try {
   382             dir.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_CREATE });
   389             dir.register(watcher, new WatchEvent.Kind<?>[]{ ENTRY_CREATE });
   383              throw new RuntimeException("ClosedWatchServiceException not thrown");
   390             throw new RuntimeException("ClosedWatchServiceException not thrown");
   384         } catch (ClosedWatchServiceException  x) {
   391         } catch (ClosedWatchServiceException  x) {
   385         }
   392         }
   386 
   393 
   387         System.out.println("OKAY");
   394         System.out.println("OKAY");
   388     }
   395     }