EventBus函数没有触发EasyMock

时间:2013-12-20 17:12:05

标签: unit-testing gwt easymock

我是新手,所以这可能是一个更简单的问题。让我问一下这个。我正在使用EasyMock测试我的MVP应用程序。我已经定义了一个EventBus。我嘲笑了一些对象。以下是代码:

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;
        }

    });

在成功方法中,我在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);
}

我正在Test Class中将ApplicationBus与ApplicationPresenter一起注册为:

   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);

}
}

当我执行测试时,我只收到了日志但事件总线没有触发事件。这是因为我在嘲笑EventBus吗?如果这是原因,那么如何使用实际的事件总线,它可以触发事件。

谢谢,

0 个答案:

没有答案
相关问题