matching List in any order when mocking method behavior with Mockito
Adding an answer for newer versions of Mockito and Java 8
when(
mock.method(argThat(t -> t.containsAll(Arrays.asList(IN_PROGRESS, ABANDONED, EXPIRED))))
).thenReturn(myValue);
If you have Mockito prior to version 2.1.0:
Use the Hamcrest containsInAnyOrder
matcher.
when(myMock.myMethod(argThat(containsInAnyOrder(IN_PROGRESS, ABANDONED, EXPIRED))))
.thenReturn(myValue);
Thank you to @kolobok for pointing out that as from Mockito 2.1.0 (which came out after I wrote this answer), this no longer works.
So for version 2.1.0 and above:
add a dependency on Hamcrest, and use the MockitoHamcrest.argThat
instead of Mockito.argThat
More detail on the breaking change with Mockito 2.1.0 is at https://www.javadoc.io/doc/org.mockito/mockito-core/2.1.0/org/mockito/ArgumentMatcher.html