jdk/test/javax/management/notification/SupportClearTest.java
changeset 4156 acaa49a2768a
parent 4155 460e37d40f12
child 4159 9e3aae7675f1
equal deleted inserted replaced
4155:460e37d40f12 4156:acaa49a2768a
     1 /*
       
     2  * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 6336980
       
    27  * @summary test 2 new methods: isListenedTo() and clear()
       
    28  * @author Shanliang JIANG
       
    29  * @run clean SupportClearTest
       
    30  * @run build SupportClearTest
       
    31  * @run main SupportClearTest
       
    32  */
       
    33 
       
    34 import javax.management.*;
       
    35 
       
    36 public class SupportClearTest {
       
    37     private static boolean received = false;
       
    38 
       
    39     public static void main(String[] args) throws Exception {
       
    40         System.out.println(">>> test 2 new methods: isListenedTo() and clear().");
       
    41 
       
    42         final NotificationListener listener = new NotificationListener() {
       
    43                 public void handleNotification(Notification n, Object hb) {
       
    44                     received = true;
       
    45                 }
       
    46             };
       
    47 
       
    48         final NotificationBroadcasterSupport broadcaster =
       
    49                 new NotificationBroadcasterSupport();
       
    50 
       
    51         System.out.println(">>> testing the method \"isListenedTo\"...");
       
    52         if (broadcaster.isListenedTo()) {
       
    53             throw new RuntimeException(
       
    54                     "Bad implementation of the method \"isListenedTo\"!");
       
    55         }
       
    56 
       
    57         broadcaster.addNotificationListener(listener, null, null);
       
    58 
       
    59         if (!broadcaster.isListenedTo()) {
       
    60             throw new RuntimeException(
       
    61                     "Bad implementation of the method \"isListenedTo\"!");
       
    62         }
       
    63 
       
    64         System.out.println(">>> testing the method \"clear\"...");
       
    65         broadcaster.removeAllNotificationListeners();
       
    66         if (broadcaster.isListenedTo()) {
       
    67             throw new RuntimeException(
       
    68                     "Bad implementation of the method \"clear\"!");
       
    69         }
       
    70 
       
    71         broadcaster.sendNotification(new Notification("", "", 1L));
       
    72 
       
    73         if (received) {
       
    74             throw new RuntimeException(
       
    75                     "Bad implementation of the method \"clear\"!");
       
    76         }
       
    77 
       
    78         System.out.println(">>> PASSED!");
       
    79     }
       
    80 }