How to check if a parameter contains two substrings using Mockito?
Just use Mockito.matches(String)
, for example:
Mockito.verify(mockMyObject).
myMethod(
Mockito.matches("(.*apple.*banana.*)|(.*banana.*apple.*)"
)
);
Since Java 8 and Mockito 2.1.0, it is possible to use Streams as follows:
Mockito.verify(mockMyObject).myMethod(
Mockito.argThat(s -> s.contains("apple") && s.contains("banana"))
);
thus improving readability