test/ObserverTest.cpp
/**
 * After an observer is removed, it should no longer receive notifications.
 */
After an observer is removed, it should no longer receive notifications.
After an observer is removed it should no longer receive notifications .
TEST(ObserverTest, removeObserver)
{
    auto observable = make_shared<Observable<TestObserver>>();
    auto obs = make_shared<MockObserver>();
    observable->addObserver(obs);
    observable->notify([=](TestObserver& o) { o.onChange(); });
    EXPECT_TRUE(VALIDATE(*obs, onChange).called());
    observable->removeObserver(obs);
    observable->notify([=](TestObserver& o) { o.onChange(); });
    EXPECT_FALSE(VALIDATE(*obs, onChange).called());
}
TEST ( ObserverTest , removeObserver ) { auto observable = make_shared < Observable < TestObserver > > ( ) ; auto obs = make_shared < MockObserver > ( ) ; observable -> addObserver ( obs ) ; observable -> notify ( [ = ] ( TestObserver & o ) { o . onChange ( ) ; } ) ; EXPECT_TRUE ( VALIDATE ( * obs , onChange ) . called ( ) ) ; observable -> removeObserver ( obs ) ; observable -> notify ( [ = ] ( TestObserver & o ) { o . onChange ( ) ; } ) ; EXPECT_FALSE ( VALIDATE ( * obs , onChange ) . called ( ) ) ; }
After an observer is removed, it should no longer receive notifications.
After an observer is removed it should no longer receive notifications .
//add the observer to this object. //notify the observers. //the observer should have been notified. //remove the observer. //notify the observers. //the observer should NOT have been notified.