コード例 #1
0
  @Test
  public void testAdaptEvent() {
    MockEventHandlerAdapter eventHandlerAdapter = new MockEventHandlerAdapter();
    MockEventHandler eventHandler = new MockEventHandler();

    PropertyChangedEvent event1 = EDPEventsFactory.eINSTANCE.createPropertyChangedEvent();
    PropertyChangedEvent event2 = EDPEventsFactory.eINSTANCE.createPropertyChangedEvent();

    eventHandler.getEvents().add(event1);
    assertEquals(0, EMFUtils.coundAdaptersOfTypeFor(event1, EventAdapter.class));
    assertEquals(0, EMFUtils.coundAdaptersOfTypeFor(event2, EventAdapter.class));
    eventHandler.eAdapters().add(eventHandlerAdapter);
    assertEquals(1, EMFUtils.coundAdaptersOfTypeFor(event1, EventAdapter.class));
    assertEquals(0, EMFUtils.coundAdaptersOfTypeFor(event2, EventAdapter.class));

    assertNotNull(EMFUtils.getAdapterOfTypeFor(event1, MockEventAdapter.class));
    assertEquals(
        eventHandlerAdapter,
        ((MockEventAdapter) EMFUtils.getAdapterOfTypeFor(event1, MockEventAdapter.class))
            .getEventHandlerAdapter());
    assertNull(EMFUtils.getAdapterOfTypeFor(event2, MockEventAdapter.class));
    eventHandler.getEvents().add(event2);
    assertNotNull(EMFUtils.getAdapterOfTypeFor(event2, MockEventAdapter.class));
    assertEquals(
        eventHandlerAdapter,
        ((MockEventAdapter) EMFUtils.getAdapterOfTypeFor(event2, MockEventAdapter.class))
            .getEventHandlerAdapter());

    assertEquals(1, EMFUtils.coundAdaptersOfTypeFor(event1, EventAdapter.class));
    assertEquals(1, EMFUtils.coundAdaptersOfTypeFor(event2, EventAdapter.class));
  }
コード例 #2
0
  @Test
  public void testEventAdded() {

    MockEventHandlerAdapter eventHandlerAdapter = new MockEventHandlerAdapter();
    MockEventHandler eventHandler = new MockEventHandler();

    PropertyChangedEvent event1 = EDPEventsFactory.eINSTANCE.createPropertyChangedEvent();
    PropertyChangedEvent event2 = EDPEventsFactory.eINSTANCE.createPropertyChangedEvent();

    assertEquals(0, eventHandlerAdapter.getManagedEventCount(event1));
    eventHandler.getEvents().add(event1);
    assertEquals(0, eventHandlerAdapter.getManagedEventCount(event1));

    eventHandler.eAdapters().add(eventHandlerAdapter);
    assertEquals(1, eventHandlerAdapter.getManagedEventCount(event1));

    assertEquals(0, eventHandlerAdapter.getManagedEventCount(event2));
    eventHandler.getEvents().add(event2);
    assertEquals(1, eventHandlerAdapter.getManagedEventCount(event2));
  }
コード例 #3
0
  @Test
  public void testEventRemoved() {
    MockEventHandlerAdapter eventHandlerAdapter = new MockEventHandlerAdapter();
    MockEventHandler eventHandler = new MockEventHandler();

    PropertyChangedEvent event1 = EDPEventsFactory.eINSTANCE.createPropertyChangedEvent();
    PropertyChangedEvent event2 = EDPEventsFactory.eINSTANCE.createPropertyChangedEvent();

    eventHandler.getEvents().add(event1);
    eventHandler.getEvents().add(event2);
    eventHandler.eAdapters().add(eventHandlerAdapter);
    assertEquals(1, eventHandlerAdapter.getManagedEventCount(event1));
    assertEquals(1, eventHandlerAdapter.getManagedEventCount(event2));

    assertEquals(1, EMFUtils.coundAdaptersOfTypeFor(event1, EventAdapter.class));
    assertEquals(1, EMFUtils.coundAdaptersOfTypeFor(event2, EventAdapter.class));

    eventHandler.getEvents().remove(event2);

    assertEquals(1, eventHandlerAdapter.getManagedEventCount(event1));
    assertEquals(0, eventHandlerAdapter.getManagedEventCount(event2));
  }