@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 300000) public void testRemoveAllVariableChangeListeners() { // 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. yoVariable.removeAllVariableChangedListeners(); resetAllObservers(); yoVariable.notifyVariableChangedListeners(); for (TestVariableChangedListener observer : this.variableChangedListeners) { assertNull(observer.getLastVariableChanged()); } }
@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()); }
@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); }