コード例 #1
0
  @ContinuousIntegrationTest(estimatedDuration = 0.0)
  @Test(timeout = 300000)
  public void testRemoveObserver() {
    // create some observers, add them to yoVariable
    int nObservers = 5;
    createVariableChangeListeners(nObservers);
    addAllListenersToYoVariable();

    // let yoVariable notify observers. Assert that they got the event.
    yoVariable.notifyVariableChangedListeners();

    for (TestVariableChangedListener observer : variableChangedListeners) {
      assertEquals(observer.getLastVariableChanged(), yoVariable);
    }

    // Remove and reset observers. Let yoVariable notify observers again. Assert that the observers
    // didn't notice anything.
    for (VariableChangedListener observer : variableChangedListeners) {
      yoVariable.removeVariableChangedListener(observer);
    }

    resetAllObservers();
    yoVariable.notifyVariableChangedListeners();

    for (TestVariableChangedListener observer : this.variableChangedListeners) {
      assertNull(observer.getLastVariableChanged());
    }
  }
コード例 #2
0
  @ContinuousIntegrationTest(estimatedDuration = 0.0)
  @Test(timeout = 300000)
  public void testNotifyVaribaleChangeListeners() {
    // create a bunch of Observers
    @SuppressWarnings("unused")
    int nObservers = 5;
    createVariableChangeListeners(5);

    // add them to the YoVariable
    yoVariable.removeAllVariableChangedListeners();
    addAllListenersToYoVariable();

    // create an observer that's not supposed to be notified.
    TestVariableChangedListener hearNoEvil = new TestVariableChangedListener();

    // make sure there's no event stored in the observers before we set
    for (TestVariableChangedListener listener : variableChangedListeners) {
      assertNull(listener.getLastVariableChanged());
    }

    assertNull(hearNoEvil.getLastVariableChanged());

    // now notify and check if the observers catch on

    yoVariable.notifyVariableChangedListeners();

    for (TestVariableChangedListener observer : variableChangedListeners) {
      assertEquals(observer.getLastVariableChanged(), yoVariable);
    }

    // make sure hearNoEvil is unaware
    assertNull(hearNoEvil.getLastVariableChanged());
  }