Package com.google.web.bindery.event.shared.testing

Examples of com.google.web.bindery.event.shared.testing.CountingEventBus


      throw e;
    }
  }

  public void testAddAndRemoveHandlers() {
    CountingEventBus eventBus = new CountingEventBus(new SimpleEventBus());
    FooEvent.register(eventBus, fooHandler1);
    FooEvent.register(eventBus, fooHandler2);
    HandlerRegistration reg1 = FooEvent.register(eventBus, adaptor1);
    eventBus.fireEvent(new FooEvent());
    assertEquals(3, eventBus.getCount(FooEvent.TYPE));
    assertFired(fooHandler1, fooHandler2, adaptor1);
    FooEvent.register(eventBus, fooHandler3);
    assertEquals(4, eventBus.getCount(FooEvent.TYPE));

    FooEvent.register(eventBus, fooHandler1);
    FooEvent.register(eventBus, fooHandler2);
    HandlerRegistration reg2 = FooEvent.register(eventBus, adaptor1);

    /*
     * You can indeed add handlers twice, they will only be removed one at a
     * time though.
     */
    assertEquals(7, eventBus.getCount(FooEvent.TYPE));
    eventBus.addHandler(BarEvent.TYPE, adaptor1);
    eventBus.addHandler(BarEvent.TYPE, barHandler1);
    eventBus.addHandler(BarEvent.TYPE, barHandler2);

    assertEquals(7, eventBus.getCount(FooEvent.TYPE));
    assertEquals(3, eventBus.getCount(BarEvent.TYPE));

    reset();
    eventBus.fireEvent(new FooEvent());
    assertFired(fooHandler1, fooHandler2, fooHandler3, adaptor1);
    assertNotFired(barHandler1, barHandler2);

    // Gets rid of first instance.
    reg1.removeHandler();
    eventBus.fireEvent(new FooEvent());
    assertFired(fooHandler1, fooHandler2, fooHandler3, adaptor1);
    assertNotFired(barHandler1, barHandler2);

    // Gets rid of second instance.
    reg2.removeHandler();
    reset();
    eventBus.fireEvent(new FooEvent());

    assertFired(fooHandler1, fooHandler2, fooHandler3);
    assertNotFired(adaptor1, barHandler1, barHandler2);

    // Checks to see if barHandler events are still working.
    reset();
    eventBus.fireEvent(new BarEvent());

    assertNotFired(fooHandler1, fooHandler2, fooHandler3);
    assertFired(barHandler1, barHandler2, adaptor1);
  }
View Full Code Here


/**
* Eponymous unit test.
*/
public class ResettableEventBusTest extends EventBusTestBase {
  public void testSimple() {
    CountingEventBus wrapped = new CountingEventBus();
    ResettableEventBus subject = new ResettableEventBus(wrapped);

    Event.Type<FooEvent.Handler> type = FooEvent.TYPE;

    assertEquals(0, wrapped.getCount(type));

    subject.addHandler(type, fooHandler1);
    subject.addHandlerToSource(type, "baker", fooHandler2);
    subject.addHandler(type, fooHandler3);

    assertEquals(3, wrapped.getCount(type));

    subject.fireEvent(new FooEvent());
    assertFired(fooHandler1, fooHandler3);
    assertNotFired(fooHandler2);

    reset();

    subject.fireEventFromSource(new FooEvent(), "baker");
    assertFired(fooHandler1, fooHandler2, fooHandler3);

    reset();

    subject.removeHandlers();
    assertEquals(0, wrapped.getCount(type));

    subject.fireEvent(new FooEvent());
    assertNotFired(fooHandler1, fooHandler2, fooHandler3);
  }
View Full Code Here

    subject.fireEvent(new FooEvent());
    assertNotFired(fooHandler1, fooHandler2, fooHandler3);
  }

  public void testNestedResetInnerFirst() {
    CountingEventBus wrapped = new CountingEventBus();
    ResettableEventBus wideScope = new ResettableEventBus(wrapped);
    ResettableEventBus narrowScope = new ResettableEventBus(wideScope);

    Event.Type<FooEvent.Handler> type = FooEvent.TYPE;

    wideScope.addHandler(type, fooHandler1);
    narrowScope.addHandler(type, fooHandler2);

    wrapped.fireEvent(new FooEvent());
    assertFired(fooHandler1, fooHandler2);

    reset();

    /*
     * When I remove handlers from the narrow resettable, it should have no
     * effect on handlers registered with the wider instance.
     */

    narrowScope.removeHandlers();

    wrapped.fireEvent(new FooEvent());
    assertFired(fooHandler1);
    assertNotFired(fooHandler2);
  }
View Full Code Here

    assertFired(fooHandler1);
    assertNotFired(fooHandler2);
  }

  public void testNestedResetOuterFirst() {
    CountingEventBus wrapped = new CountingEventBus();
    ResettableEventBus wideScope = new ResettableEventBus(wrapped);
    ResettableEventBus narrowScope = new ResettableEventBus(wideScope);

    Event.Type<FooEvent.Handler> type = FooEvent.TYPE;

    wideScope.addHandler(type, fooHandler1);
    narrowScope.addHandler(type, fooHandler2);

    wrapped.fireEvent(new FooEvent());
    assertFired(fooHandler1, fooHandler2);

    reset();

    /*
     * When I remove handlers from the first resettable, handlers registered by
     * the narrower scoped one that wraps it should also be severed.
     */

    wideScope.removeHandlers();

    wrapped.fireEvent(new FooEvent());
    assertNotFired(fooHandler1);
    assertNotFired(fooHandler2);
  }
View Full Code Here

    @Before
    public void presenterTestSetUp()
    {
        td = new TestData();
        events = new Stack<Event<?>>();
        eventBus = new CountingEventBus();
        scheduler = new StubScheduler();
        placeManager = mock(PlaceManager.class);
    }
View Full Code Here

TOP

Related Classes of com.google.web.bindery.event.shared.testing.CountingEventBus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.