ContainedListTest.java 文件源码

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

项目:modelgen 作者:
@Test
public void testAdd() throws Exception {

    Parent parent = new Parent();
    Child child = new Child();
    parent.children().getChangeSupport()
            .addPropertyChangeListener(new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    assertTrue(evt instanceof IndexedPropertyChangeEvent);
                    IndexedPropertyChangeEvent iEvt = (IndexedPropertyChangeEvent) evt;
                    assertEquals(0, iEvt.getIndex());
                    assertNull(iEvt.getOldValue());
                    assertSame(child, iEvt.getNewValue());
                    assertSame(parent, child.getParent());
                    throw new RuntimeException("All is well!");
                }
            });
    try {
        parent.children().add(child);
        fail("Property change listener not notified");
    } catch (RuntimeException e) {
        assertEquals("All is well!", e.getMessage());
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号