NotificationBroadcasterSupportTest.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:freeVM 作者:
/**
 * Test for the method
 * addNotificationListener(javax.management.NotificationListener,
 * javax.management.NotificationFilter, java.lang.Object)
 * 
 * @see javax.management.NotificationBroadcasterSupport#addNotificationListener(javax.management.NotificationListener,
 *      javax.management.NotificationFilter, java.lang.Object)
 */
public final void testAddNotificationListener() {
    Hello h = new Hello();
    // Test exception.
    try {
        h.addNotificationListener(null, null, null);
        fail("IllegalArgumentException not thrown!");
    } catch (Throwable ex) {
        assertTrue("Wrong exception thrown: " + ex,
            (ex instanceof IllegalArgumentException));
    }

    h.addNotificationListener(this, null, handback);
    h.sayHello();
    assertNotNull("Notification has not been received!", n);
    assertEquals("Wrong handback object received!", handback, receivedHB);

    n = null;
    receivedHB = null;
    h = new Hello();
    NotificationFilterSupport f = new NotificationFilterSupport();
    f.enableType(AttributeChangeNotification.ATTRIBUTE_CHANGE);
    h.addNotificationListener(this, f, null);
    h.setName("New name");
    assertNotNull("Notification has not been received!", n);
    assertTrue("Wrong handback object received!", receivedHB == null);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号