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

Handle null in argument matchers. #135

Merged
merged 1 commit into from
Dec 10, 2016
Merged

Conversation

nhaarman
Copy link
Collaborator

@nhaarman nhaarman commented Dec 8, 2016

When stubbing with argument matchers, the following
scenario would cause a NullPointerException:

whenever(mock.doSomething(argThat { })).thenReturn("")
whenever(mock.doSomething(argThat { })).thenReturn("")

The second argThat invocation returns a null value,
which gets propagated into the function passed to the
first argThat invocation.

This commit filters null values to always evaluate to
false when provided to an argument matcher.

Fixes #133.
Fixes #134 by throwing a descriptive error.

When stubbing with argument matchers, the following
scenario would cause a NullPointerException:

```
whenever(mock.doSomething(argThat { })).thenReturn("")
whenever(mock.doSomething(argThat { })).thenReturn("")
```

The second `argThat` invocation returns a `null` value,
which gets propagated into the function passed to the
first `argThat` invocation.

This commit filters `null` values to always evaluate to
`false` when provided to an argument matcher.
@nhaarman nhaarman merged commit 263344f into dev Dec 10, 2016
@nhaarman nhaarman deleted the handle-null-in-argumentmatcher branch December 10, 2016 14:48
@nhaarman nhaarman added this to the 1.0.1 milestone Dec 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant