/** Make sure that all events get fired to all listeners. */
  public void testVeryBasicChain() {
    SequenceDependenciesEventPublisher publisher = new SequenceDependenciesEventPublisher();
    SimpleSubjectListener a = new SimpleSubjectListener("A", publisher);
    SimpleSubjectListener b = new SimpleSubjectListener("B", publisher);
    SimpleSubjectListener c = new SimpleSubjectListener("C", publisher);

    a.setValue("apple");
    assertEquals("apple", a.getValue());
    assertEquals(null, b.getValue());
    assertEquals(null, c.getValue());

    a.addListener(b);
    a.setValue("banana");
    assertEquals("banana", a.getValue());
    assertEquals("[A:banana]", b.getValue());
    assertEquals(null, c.getValue());

    a.addListener(c);
    a.setValue("chocolate");
    assertEquals("chocolate", a.getValue());
    assertEquals("[A:chocolate]", b.getValue());
    assertEquals("[A:chocolate]", c.getValue());

    a.removeListener(b);
    a.setValue("ducks");
    assertEquals("ducks", a.getValue());
    assertEquals("[A:chocolate]", b.getValue());
    assertEquals("[A:ducks]", c.getValue());

    c.addListener(b);
    a.setValue("elephants");
    assertEquals("elephants", a.getValue());
    assertEquals("[C:[A:elephants]]", b.getValue());
    assertEquals("[A:elephants]", c.getValue());

    c.setValue("foxes");
    assertEquals("elephants", a.getValue());
    assertEquals("[C:foxes]", b.getValue());
    assertEquals("foxes", c.getValue());

    a.removeListener(c);
    a.setValue("gorillas");
    assertEquals("gorillas", a.getValue());
    assertEquals("[C:foxes]", b.getValue());
    assertEquals("foxes", c.getValue());

    a.addListener(c);
    a.setValue("horses");
    assertEquals("horses", a.getValue());
    assertEquals("[C:[A:horses]]", b.getValue());
    assertEquals("[A:horses]", c.getValue());
  }
  /** Make sure we throw an exception when attempting to remove something that's not a listener. */
  public void testUnknownRemoveThrowsException() {
    SequenceDependenciesEventPublisher publisher = new SequenceDependenciesEventPublisher();
    SimpleSubjectListener a = new SimpleSubjectListener("A", publisher);
    SimpleSubjectListener b = new SimpleSubjectListener("B", publisher);
    SimpleSubjectListener c = new SimpleSubjectListener("C", publisher);

    // add a listener
    a.addListener(b);
    try {
      a.removeListener(c);
      fail("No exception thrown when removing a non-existent listener");
    } catch (IllegalArgumentException e) {
      // expected
    }

    // remove the other listener, this shouldn't throw
    a.removeListener(b);
  }
 public void run() {
   subject.removeListener(listener);
 }