Question

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(?)

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top