I use Mockito to write unit test in Java, and I would like to verify that the specific method is the last one to call the object.
I am doing something similar in the test code:
row.setSomething(value); row.setSomethingElse(anotherValue); row.editABunchMoreStuff(); row.saveToDatabase();
In my layout, I don’t care about the order in which I edit everything in the line, but it is very important that I do not try to do anything else after I save it. Is there a good way to do this?
Please note that I am not looking for confirmation of NoMoreInteractions: it does not confirm that saveToDatabase is the last thing called and it also fails if I call something on a line that I am not explicitly checking. I would like to say something like:
verify(row).setSomething(value); verify(row).setSomethingElse(anotherValue); verifyTheLastThingCalledOn(row).saveToDatabase();
If this helps, I go to Mockito from the JMock test that did this:
row.expects(once()).method("saveToDatabase").id("save"); row.expects(never()).method(ANYTHING).after("save");
java unit-testing mockito mocking
Moss Collum Feb 04 '09 at 17:00 2009-02-04 17:00
source share