Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stubbing with some AdditionalMatchers can NPE with null actuals #457

Closed
kidnme opened this issue Jun 23, 2016 · 2 comments
Closed

Stubbing with some AdditionalMatchers can NPE with null actuals #457

kidnme opened this issue Jun 23, 2016 · 2 comments
Labels

Comments

@kidnme
Copy link

kidnme commented Jun 23, 2016

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.AdditionalMatchers.leq;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Test;

public class BlahTest
{
    @Test
    public void test()
    {
        final BoolResult mockBoolResult = mock(BoolResult.class);

        when(mockBoolResult.getResult(eq(5))).thenReturn(true);  // Succeeds as expected
        when(mockBoolResult.getResult(leq(5))).thenReturn(true); // Fails with an NPE - as of v2.0.64 - unexpected!

        assertThat(mockBoolResult.getResult(null), is(false));
    }

    interface BoolResult
    {
        boolean getResult(Integer value);
    }
}
@ChristianSchwarz
Copy link
Contributor

Seems to be related to my removal of HandyReturnValues. I will look into it!
Thanks for reporting! Did you found more Matcher that misbehave like that?

@ChristianSchwarz
Copy link
Contributor

ChristianSchwarz commented Jun 23, 2016

@kidnme
I can't reproduce it with mockito/master [HEAD]. Can you test it with v2.0.71-beta ?
Edit: There is no issue with the matchers but with the implementation of CompareTo.

ChristianSchwarz pushed a commit to ChristianSchwarz/mockito-lambda that referenced this issue Jun 23, 2016
CompareTo compares now only agains instances of Comparable
@bric3 bric3 added the bug label Jun 24, 2016
ChristianSchwarz pushed a commit to ChristianSchwarz/mockito-lambda that referenced this issue Jun 24, 2016
ChristianSchwarz pushed a commit to ChristianSchwarz/mockito-lambda that referenced this issue Jun 24, 2016
ChristianSchwarz pushed a commit to ChristianSchwarz/mockito-lambda that referenced this issue Jun 24, 2016
ChristianSchwarz pushed a commit to ChristianSchwarz/mockito-lambda that referenced this issue Jul 1, 2016
ChristianSchwarz pushed a commit to ChristianSchwarz/mockito-lambda that referenced this issue Jul 1, 2016
ArgumentsComparator

This avoids ClassCastExceptions and NullPointerExceptions.
ChristianSchwarz pushed a commit to ChristianSchwarz/mockito-lambda that referenced this issue Jul 1, 2016
ArgumentsComparator

Added tests to HashCodeAndEqualsSafeSetTest to satisfy codecov
@TimvdLippe TimvdLippe removed the ready label Jul 5, 2016
ChristianSchwarz pushed a commit to ChristianSchwarz/mockito-lambda that referenced this issue Jul 7, 2016
commit 6e8a4779cedc046d1343c9067f5fd15fcbeee80a
Author: Tim van der Lippe <tvanderlippe@gmail.com>
Date:   Tue Jul 5 16:55:04 2016 +0200

    Add two tests to verify subclass extension for generic type retrieval

commit e39c2bc
Author: Christian Schwarz <chriss.dev@github>
Date:   Fri Jul 1 22:16:24 2016 +0200

    Fixes mockito#457 added type compability checks to CompareTo and
    ArgumentsComparator

    Added tests to HashCodeAndEqualsSafeSetTest to satisfy codecov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants