I am beginning with mockito and wondering how to fake adding an observer. I want to write a test that ensures that the observer count has increased after a function call.
example testing code:
MyClassUnderTest instance = new MyClassUnderTest();
AudioDeviceManager adm = mock(AudioDeviceManager.class);
assertEquals(adm.countObservers(), 0);
instance.setup(adm, microphone);
//Inside the setup function, microphone is added as an observer
//to the device manager: adm.addObserver(microphone);
assertEquals(adm.countObservers(), 1);
Since adm is a mock, I know I have to define the logic of addObserver but I do not know what to –
when(adm.addObserver(Observer o)).then(?)
brian,
use verify. For example instead of the assert, run
and check the first chapter of http://mockito.googlecode.com/svn/branches/1.5/javadoc/org/mockito/Mockito.html
Cheers,
a.