The actual importLogBean has a status of 9, one of the places where this is
set is in the following code:
catch (Exception e) {
// 9 = failed - exception
if (importLogBean != null)
importLogBean.setStatus(9);
}
Perhaps an exception is happening in the test because there is setup involved
which is done in your app, but not in the test. For example, perhaps
ImportHandlerFactory.singleton() throws an exception which is then being
caught and masked. My suggestion is to debug the test and see if an exception
you didn't expect is thrown, or even put in an e.printStackTrace(). It may
highlight a difference in setup between the test and the running app.
HTH,
Graham
I think the problem is, that you are altering the captured object
after handing it to the mock.
So when you call the verify, the object is by then altered to status==9.
An EasyMock-like mock would work better for this case. EasyMock
verifies the calls, when they happen, not afterwards.
I don't know off the top of my head, whether this can be done with
mockito, though.
Greetings,
Malte
The idea would have still held true for the line:
importLogBean = createResume(importType, date);
... but now I realise, not for the include() method, only the alter() method.
Nope, really can't see from the example how the status can change between
these two lines:
importLogBean.setStatus(1);
importLogDao.include(importLogBean);
Sorry I couldn't help, if you figure it out let me know what the problem was.
~ Graham
That's a good point, if the call to alter() sets the status to 9 it may be
causing the problem. If you change the line:
verify(importLogDao).include(initialLog);
to:
verify(importLogDao).include(new ImportLogBeen(currentDate, importType);
Does it work? (This is assuming a correct equals() method.
~ Graham
In that part of test : verify(importLogDao).include(initialLog);I think the problem is, that you are altering the captured object after handing it to the mock. So when you call the verify, the object is by then altered to status==9.
Hi, Szczepan ! My business classes, as ImportManager, are singleton (managed by our DI framework). So I can't have class atributes on it. I just have methods with java beans (mutable) being passed as arguments to them. So, if I cannot use verify() to check if a internal method of my manager class was called, ex: verify(importLogDao).include(initialLog);Today, is there a way to use Mockito to test those beans state inside my methods?
:-) man, it is really dificult for a brazilian just to imagine how could I speach your name !!! :-D
:-) man, it is really dificult for a brazilian just to imagine how could I speach your name !!! :-Dc'mon man, it's just a couple of zeds more =)
Today, is there a way to use Mockito to test those beans state inside my methods?I would probably make ImportLogBean immutable (which probably should be immutable anyway - It smells funny that you create log, send an it to importLogDao and then you change the state of log....). Or at least create a different log if I need different status.