I'm trying to learn Mockito framework and implementing some mocks. Currently, I want to use ArgumentMatcher to check if the passed object matches. I saw that in the past this was possible by creating a new class that extends ArgumentMatcher. However, now it's possible to use Java 8 lambda functions. This is how I'm trying to implement it:
private ArgumentMatcher<User> matchUser(User user) {
return u -> u != null && user.getId() == u.getId();
}
IntelliJ is giving me an error, as it's telling that u doesn't have the getId method.
Should't u type be inferred to User?
You have Mockito version 1.x, where ArgumentMatcher is an abstract class. As of Mockito 2.x, they changed it to be an interface, allowing to use lambdas.
The source code of ArgumentMatcher shows that:
release-2.x on GitHubrelease-1.x on GitHubIf you fix your dependencies to a more recent version of Mockito, it'll work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With