You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PR open] Add feature to verify static methods calls in order #2548
TL;DR Mockito doesn't allow verifying static methods calls in order. I have implemented this feature here: #2549. If possible, I'd like to contribute; or discuss other ways to achieve the same.
This issue is about verifying static methods calls in order. I'm aware of the InOrder class, but we can't pass a MockedStatic instance. I had a closer look, and we can pass to it a Class instance. But the InOrder interface is not powerful enough to verify that a static method has been called:
public interface InOrder {
<T> T verify(T mock);
<T> T verify(T mock, VerificationMode mode);
void verifyNoMoreInteractions();
}
To verify static calls, using method references and lambdas, we likely need two more methods in the InOrder interface, with signatures similar to MockedStatic#verify:
What do you think of the InOrder interface exposing two methods to deal with the MockedStatic objects that accept both the MockedStatic and the Verification instances to use? Like the following:
I made the above changes, and we can verify static methods, together with instance methods too. I have updated the tests as well in my PR.
Let me know if you are aware of other ways to achieve the same. If it is not doable, then please share your thoughts about the above, and if I can contribute in case.
changed the title [-]Add feature to verify static methods calls in order[/-][+][PR open] Add feature to verify static methods calls in order[/+]on Feb 1, 2022
As a Mockito user I would love to have this new feature @mirkoalicastro
I made it more clear that there is already a possible implementation with the mentioned PR, which includes tests as well, of course. I hope someone will look into this.
Sorry I hadn't gotten to it. I responded to the PR, it's looking good! We mainly need to figure out how we are handling the Class that is matching the mockedStatic, but I think in that case we should be passing that into the inOrder() method call. Let's iterate on the PR and see where it goes!
Activity
Fixes mockito#2548 : Makes InOrder able to verify static methods
rob93c commentedon Feb 1, 2022
As a Mockito user I would love to have this new feature @mirkoalicastro
[-]Add feature to verify static methods calls in order[/-][+][PR open] Add feature to verify static methods calls in order[/+]mirkoalicastro commentedon Feb 1, 2022
I made it more clear that there is already a possible implementation with the mentioned PR, which includes tests as well, of course. I hope someone will look into this.
mirkoalicastro commentedon Feb 12, 2022
@TimvdLippe Are you able to provide some feedback on this / to involve relevant people? Many thanks.
TimvdLippe commentedon Feb 15, 2022
Sorry I hadn't gotten to it. I responded to the PR, it's looking good! We mainly need to figure out how we are handling the
Classthat is matching themockedStatic, but I think in that case we should be passing that into theinOrder()method call. Let's iterate on the PR and see where it goes!Fixes #2548: make InOrder able to verify static methods (#2549)