コード例 #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 testAddVariableChangeListener() {
   // remove all observers, then add one new observer, and check if it can be removed without
   // exceptions.
   yoVariable.removeAllVariableChangedListeners();
   TestVariableChangedListener listener = new TestVariableChangedListener();
   yoVariable.addVariableChangedListener(listener);
   yoVariable.removeVariableChangedListener(listener);
 }
コード例 #3
0
 @ContinuousIntegrationTest(estimatedDuration = 0.0)
 @Test(timeout = 300000)
 public void testRemoveObserverNonExistent1() {
   // make sure removing an observer that wasn't added throws an exception.
   try {
     yoVariable.removeVariableChangedListener(new TestVariableChangedListener());
     fail();
   } catch (NoSuchElementException e) {
     // pass.
   }
 }
コード例 #4
0
 @ContinuousIntegrationTest(estimatedDuration = 0.0)
 @Test(timeout = 300000, expected = NoSuchElementException.class)
 public void testRemoveObserverNonExistent2() {
   // make sure removing an observer that wasn't added throws an exception.
   //      try
   {
     createVariableChangeListeners(5);
     addAllListenersToYoVariable();
     yoVariable.removeVariableChangedListener(new TestVariableChangedListener());
     // fail();
   }
   //      catch (NoSuchElementException e)
   {
     // pass.
   }
 }