NullPointerException when using argThat() for long parameter in verify
See original GitHub issueA minimal code example:
@Test
public void shouldNotBeBroken() throws Exception {
TakesALong takesALong = mock(TakesALong.class);
verify(takesALong).call(argThat(CoreMatchers.equalTo(11L)));
}
static interface TakesALong {
void call(long l);
}
This leads to an NPE logged as happening at the ‘verify’ call, which made me think that the the result of verify(takesALong)
was null, but it seems like the NPE has a somewhat incomplete stack trace. Variations that don’t show this problem include:
- changing the interface to take a
Long
instead of along
, or - using
longThat(Matcher<Long>)
instead ofargThat()
If it is considered an error to use argThat
where you’re passing in a long, then I think at least there should be a better error message.
Issue Analytics
- State:
- Created 9 years ago
- Comments:18 (17 by maintainers)
Top Results From Across the Web
NullPointerException when working with ArgumentMatcher
You have a NullPointerException because the method signature is using a native type, and you are using Matchers.argThat , which returns an ...
Read more >NullPointerException using two given with argThat on same ...
Hi people, I have a classe that use a Dao's method that receive a List as parameter. I need two diffent responses depend...
Read more >ArgumentMatchers (Mockito 3.8.0 API) - Javadoc.io
If you are using argument matchers, all arguments have to be provided by matchers. E.g: (example shows verification but the same applies to...
Read more >MockitoHamcrest (Mockito 3.9.0 API) - Javadoc
Allows matching arguments with hamcrest matchers. ... Note the NullPointerException auto-unboxing caveat described ... MockitoHamcrest() ...
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Unit tests are designed to test the behavior of specific classes or methods ... Here we create the hasLuck argument matcher and use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree that better error message would be great. Do you have suggestions how to implement it?
There’s a ‘longThat’ method that can be used in this context.
Hope that helps!
Again, something against Eclipse. It’s not the first bad bug using Eclipse compiler.
– Brice
On Wed, Aug 17, 2016 at 12:39 PM +0200, “Christian Schwarz” notifications@github.com wrote:
Jup!
It’s a bug in eclipse JDT that only occures with a non standard JRE execution environment and compiler compliance setup. I filed an issue for the JDT-Team: Bug 499817
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.