You mention 2 problems that block you from using inOrder
- you don't know which methods have been called before
- you have private methods
None of these 2 are valid reasons. It is always possible to use inOrder.
Whatever your method needs to do should depend on 2 things only:
- The parameters passed to the method.
- State. And in a well designed class that should be restricted to the state of the object who's method you are calling.
Any possible combination of data in the parameters and the state of the object can be simulated using mockups. And anything that happens inside your method (method calls being done) should be known by you, otherwise you would not know what you are trying to test.
So, if any methods, private or not were called before, there are 2 possibilities:
- It has impact on your method. In that case it should be visible in the state of the object and you can initialize your test object and your mockups differently in multiple test cases to test the different possibilities.
- It has no impact on your method. In that case, it obviously can't be a problem for your test.
The only situation where you can have some trouble is when static methods of other classes are called directly or static fields are read directly and their state can have impact. In those cases, it is best to isolate such calls in a separate method in a class that doesn't contain much logic and acts as a wrapper. That way you have a wrapper which you can mock and that solves the problem.
A special case are constructors which are called. A constructor is a special sort of static method. And the above mentioned approach for statics corresponds to creating a factory class to construct the objects. But a constructor creates something that didn't have a state yet. And that means it's state can not be unpredictable/problematic for your test. But even then a factory that can be mocked can be very useful to avoid unnecessary complexity and dependencies in tests.
Conclusions:
When you know what your method is doing and it doesn't use statics from other classes directly, you can always check everything using inOrder and add a call to verifyNoMoreInteractions in the end to make sure the last method you verified was the last one that was called.
And even when it does use statics from other classes directly which complicate your tests, that is a design issue that can easily be solved.