I'm trying to test some legacy code, using Mockito.
I want to stub a FooDao
that is used in production as follows:
foo = fooDao.getBar(new Bazoo());
I can write:
when(fooDao.getBar(new Bazoo())).thenReturn(myFoo);
But the obvious problem is that getBar()
is never called with the same Bazoo
object that I stubbed the method for. (Curse that new
operator!)
I would love it if I could stub the method in a way that it returns myFoo
regardless of the argument. Failing that, I'll listen to other workaround suggestions, but I'd really like to avoid changing the production code until there is reasonable test coverage.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…