public void testCreatesChangeMonitorWhenProjectIsCreated() throws CoreException {
    IProjectChangeMonitorFactory factory = getFactory();
    expect(factory.createProjectChangeMonitor((IProject) anyObject()))
        .andReturn(createMock(IResourceChangeListener.class));
    replay(factory);

    TestHaskellProject prj = new TestHaskellProject("createsChangeMonitorProject", getCorePrefs());
    prj.destroy();

    verify(factory);
  }
  public void testCreatesProjectMonitorsForLoadedWorkspace() throws CoreException {
    TestHaskellProject prj = new TestHaskellProject("myproject", getCorePrefs());

    IProjectChangeMonitorFactory factory = createMock(IProjectChangeMonitorFactory.class);
    expect(factory.createProjectChangeMonitor(prj.getPlatformProject()))
        .andReturn(createNiceMock(IResourceChangeListener.class));
    expect(factory.createProjectChangeMonitor((IProject) anyObject()))
        .andReturn(createNiceMock(IResourceChangeListener.class))
        .atLeastOnce(); // projects might already exist in the workspace
    checkOrder(factory, false);
    replay(factory);

    WorkspaceChangeMonitor mon = new WorkspaceChangeMonitor(factory);
    mon.observeChangesOn(getWorkspace());

    getWorkspace().removeResourceChangeListener(mon);

    verify(factory);
  }
  public void testDelegatesProjectEventsToCorrespondingMonitor() throws CoreException {
    IResourceChangeListener fstMonitor = createNiceMock(IResourceChangeListener.class);
    IResourceChangeListener sndMonitor = createNiceMock(IResourceChangeListener.class);
    expect(getFactory().createProjectChangeMonitor((IProject) anyObject())).andReturn(fstMonitor);
    expect(getFactory().createProjectChangeMonitor((IProject) anyObject())).andReturn(sndMonitor);
    replay(getFactory());

    TestHaskellProject fstPrj = new TestHaskellProject("first-project", getCorePrefs());
    TestHaskellProject sndPrj = new TestHaskellProject("second-project", getCorePrefs());

    try {
      fstMonitor.resourceChanged((IResourceChangeEvent) anyObject());
      replay(fstMonitor, sndMonitor);
      fstPrj.createSourceFile("Factorial.hs", "module Factorial where\n\n");
      verify(getFactory(), fstMonitor, sndMonitor);
    } finally {
      fstPrj.destroy();
      sndPrj.destroy();
    }
  }