Unit testing 事件总线功能未触发EasyMock
我是新手,所以这可能是一个更简单的问题。让我问这个。我正在使用EasyMock测试我的MVP应用程序。我定义了一个事件总线。我模仿了一些物体。代码如下:Unit testing 事件总线功能未触发EasyMock,unit-testing,gwt,easymock,Unit Testing,Gwt,Easymock,我是新手,所以这可能是一个更简单的问题。让我问这个。我正在使用EasyMock测试我的MVP应用程序。我定义了一个事件总线。我模仿了一些物体。代码如下: service.getAllBooks(isA(MethodCallback.class)); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwab
service.getAllBooks(isA(MethodCallback.class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
final Object[] currentArguments = getCurrentArguments();
MethodCallback callback = ((MethodCallback)currentArguments[1]);
List<Book> model = new ArrayList<Book>();
Book modelItem = new Book();
model.add(modelItem);
Method method = org.easymock.classextension.EasyMock.createNiceMock(Method.class);
callback.onSuccess(method, model);
return null;
}
});
当我执行测试时,我只收到日志,但事件总线没有触发事件。这是因为我在嘲笑EventBus吗?如果这就是原因,那么如何使用实际的事件总线来触发事件
谢谢,您能否输入一些代码,说明如何注册事件总线?也可以参考这个示例链接。请查看编辑的帖子。在安装程序中,我为EventBus创建模拟,然后在Presenter中设置事件总线。程序正确吗?
public void onSuccess(Method method, List<Book> response) {
log.info("Received response.");
getEventBus().receivedResponse(reponse);
}
@Events(startPresenter = ApplicationPresenter.class, ginModules = UiGinClientModule.class)
public interface UiEventBus extends EventBusWithLookup
{
@Start
@Event(handlers={ ApplicationPresenter.class })
void start();
@Event(handlers={ ApplicationPresenter.class })
void receivedResponse(List<Book> response);
}
public class ApplicationPresenterTest {
ApplicationPresenter applicationPresenter;
IApplicationView applicationView;
MyRestService mService;
UiEventBus eventBus;
@Before
public void setUp() throws Exception
{
applicationView = createStrictMock(IApplicationView.class);
eventBus = createStrictMock(UiEventBus.class);
applicationPresenter = new ApplicationPresenter();
applicationPresenter.setEventBus(eventBus);
mService = createStrictMock(MyRestService.class);
}
}