【发布时间】:2016-06-23 01:59:00
【问题描述】:
我需要测试一些与事件总线的交互。我已将所有参数包装在 Event 类中。问题是当我想验证事件时,我必须在测试中创建事件对象并提供所有参数。我宁愿只指定重要的参数,以明确哪些参数很重要。
def "initial layout should call page events"() {
given: "register for event"
def listener = Mock(Closure)
eventBus.registerForEvent(PageVisibilityChangedEvent, listener)
when: "viewport twice the size of our pages and can fit 2 pages"
worldport.updateScreenSize(new IntSizeImpl(200, 400))
then: "after the initial layout pages 0 and 1 should have become visible"
1 * listener.call(new PageVisibilityChangedEvent(_, 0, _, Visibility.VISIBLE, _))
1 * listener.call(new PageVisibilityChangedEvent(_, 1, _, Visibility.VISIBLE, _))
0 * _
}
【问题讨论】: