spring - Mocking java objects gives class cast exceptions -
i have interface fly
, class duck
implements fly
.
interface fly { getwingsize(); } public class duck implements fly { @override int getwingsize(){ return 1; } }
in controller class, when try use following:
fly flyanimal = animal.getflyinganimal(); ((duck) flyanimal).getwingsize();
it works fine, in junit, gives class cast exception. using powermockito.
in code casting concrete class (duck). in general, mock interfaces. test case might have mocked interface fly.
it should work fine if replace ((duck) fly).getwingsize();
fly.getwingsize();
Comments
Post a Comment