java - mockito - faking addObserver -
i beginning mockito , wondering how fake adding observer. want write test ensures observer count has increased after function call.
example testing code:
myclassundertest instance = new myclassundertest(); audiodevicemanager adm = mock(audiodevicemanager.class); assertequals(adm.countobservers(), 0); instance.setup(adm, microphone); //inside setup function, microphone added observer //to device manager: adm.addobserver(microphone); assertequals(adm.countobservers(), 1);
since adm mock, know have define logic of addobserver
not know - when(adm.addobserver(observer o)).then(?)
brian,
use verify. example instead of assert, run
verify(adm).countobservers( anyobject)
and check first chapter of http://mockito.googlecode.com/svn/branches/1.5/javadoc/org/mockito/mockito.html
cheers, a.
Comments
Post a Comment