Search in sources :

Example 1 with AddElementPropertyChangeEvent

use of ch.acanda.eclipse.pmd.domain.DomainModel.AddElementPropertyChangeEvent in project eclipse-pmd by acanda.

the class WorkspaceModelTest method addFiresAnAddElementPropertyChangeEvent.

/**
 * Verifies that an event is fired when adding a project model.
 */
@Test
public void addFiresAnAddElementPropertyChangeEvent() {
    final WorkspaceModel model = new WorkspaceModel();
    final boolean[] eventFired = new boolean[1];
    final ProjectModel element = new ProjectModel("Foo");
    model.addPropertyChangeListener(WorkspaceModel.PROJECTS_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            eventFired[0] = true;
            assertTrue("The event should be an AddElementPropertyChangeEvent", event instanceof AddElementPropertyChangeEvent);
            assertSame("Event's added element", element, ((AddElementPropertyChangeEvent) event).getAddedElement());
            assertNull("Event's old value should be null", event.getOldValue());
            assertSame("Event's new value should be the added element", element, event.getNewValue());
        }
    });
    model.add(element);
    assertTrue("An event should be fired when adding a project model", eventFired[0]);
}
Also used : RemoveElementPropertyChangeEvent(ch.acanda.eclipse.pmd.domain.DomainModel.RemoveElementPropertyChangeEvent) AddElementPropertyChangeEvent(ch.acanda.eclipse.pmd.domain.DomainModel.AddElementPropertyChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) AddElementPropertyChangeEvent(ch.acanda.eclipse.pmd.domain.DomainModel.AddElementPropertyChangeEvent) Test(org.junit.Test)

Aggregations

AddElementPropertyChangeEvent (ch.acanda.eclipse.pmd.domain.DomainModel.AddElementPropertyChangeEvent)1 RemoveElementPropertyChangeEvent (ch.acanda.eclipse.pmd.domain.DomainModel.RemoveElementPropertyChangeEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Test (org.junit.Test)1