Java Code Examples for com.google.web.bindery.event.shared.EventBus#fireEvent()

The following examples show how to use com.google.web.bindery.event.shared.EventBus#fireEvent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventBinderTest.java    From gwteventbinder with Apache License 2.0 6 votes vote down vote up
public void testEventBinder() {
  EventBus eventBus = new SimpleEventBus();
  TestPresenter presenter = new TestPresenter();
  TestPresenter.MyEventBinder binder = GWT.create(TestPresenter.MyEventBinder.class);
  binder.bindEventHandlers(presenter, eventBus);

  // Test one event
  assertEquals(0, presenter.firstEventsHandled);
  eventBus.fireEvent(new FirstEvent());
  assertEquals(1, presenter.firstEventsHandled);
  assertEquals(1, presenter.firstEventsWithoutParameterHandled);
  assertEquals(1, presenter.firstAndSecondEventsHandled);

  // Test another event twice
  assertEquals(0, presenter.secondEventsHandled);
  eventBus.fireEvent(new SecondEvent());
  eventBus.fireEvent(new SecondEvent());
  assertEquals(2, presenter.secondEventsHandled);
  assertEquals(3, presenter.firstAndSecondEventsHandled);
}
 
Example 2
Source File: EventBinderTest.java    From gwteventbinder with Apache License 2.0 6 votes vote down vote up
public void testEventBinder_withHandlersInSuperclass() {
  EventBus eventBus = new SimpleEventBus();
  SubPresenter presenter = new SubPresenter();
  SubPresenter.MyEventBinder binder = GWT.create(SubPresenter.MyEventBinder.class);
  binder.bindEventHandlers(presenter, eventBus);

  eventBus.fireEvent(new FirstEvent());
  eventBus.fireEvent(new SecondEvent());
  eventBus.fireEvent(new ThirdEvent());

  // FirstEvent has a handler in both classes, so it should be handled twice
  assertEquals(1, presenter.firstEventsHandled);
  assertEquals(1, presenter.firstEventsWithoutParameterHandled);
  assertEquals(1, presenter.subclassFirstEventsHandled);

  // SecondEvent's handler is overridden in the subclass, so it should only be handled there
  assertEquals(0, presenter.secondEventsHandled);
  assertEquals(1, presenter.subclassSecondEventsHandled);

  // ThirdEvent is only handled in the superclass
  assertEquals(1, presenter.thirdEventsHandled);

  // First+Second events are handled in superclass
  assertEquals(2, presenter.firstAndSecondEventsHandled);
}
 
Example 3
Source File: EventBinderTest.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
public void testEventBinder_unbindEventHandlers() {
  EventBus eventBus = new SimpleEventBus();
  TestPresenter presenter = new TestPresenter();
  TestPresenter.MyEventBinder binder = GWT.create(TestPresenter.MyEventBinder.class);
  HandlerRegistration registration = binder.bindEventHandlers(presenter, eventBus);
  assertEquals(0, presenter.firstEventsHandled);
  assertEquals(0, presenter.firstEventsWithoutParameterHandled);
  assertEquals(0, presenter.secondEventsHandled);

  // Before unregistering
  eventBus.fireEvent(new FirstEvent());
  eventBus.fireEvent(new SecondEvent());
  assertEquals(1, presenter.firstEventsHandled);
  assertEquals(1, presenter.firstEventsWithoutParameterHandled);
  assertEquals(1, presenter.secondEventsHandled);
  assertEquals(2, presenter.firstAndSecondEventsHandled);

  // After unregistering
  registration.removeHandler();
  eventBus.fireEvent(new FirstEvent());
  eventBus.fireEvent(new SecondEvent());
  assertEquals(1, presenter.firstEventsHandled);
  assertEquals(1, presenter.firstEventsWithoutParameterHandled);
  assertEquals(1, presenter.secondEventsHandled);
  assertEquals(2, presenter.firstAndSecondEventsHandled);

  // After re-registering
  binder.bindEventHandlers(presenter, eventBus);
  eventBus.fireEvent(new FirstEvent());
  eventBus.fireEvent(new SecondEvent());
  assertEquals(2, presenter.firstEventsHandled);
  assertEquals(2, presenter.firstEventsWithoutParameterHandled);
  assertEquals(2, presenter.secondEventsHandled);
  assertEquals(4, presenter.firstAndSecondEventsHandled);
}
 
Example 4
Source File: EventBinderTest.java    From gwteventbinder with Apache License 2.0 5 votes vote down vote up
public void testEventBinder_inDifferentPackage() {
  EventBus eventBus = new SimpleEventBus();
  TestPresenter presenter = new TestPresenter();
  SomeActivity.SomeEventBinder binder = GWT.create(SomeActivity.SomeEventBinder.class);
  binder.bindEventHandlers(presenter, eventBus);

  // Test one event
  assertEquals(0, presenter.firstEventsHandled);
  eventBus.fireEvent(new FirstEvent());
  assertEquals(1, presenter.firstEventsHandled);
}