You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
- 5Thanks for this writeup. A NullPointerException with the when/thenReturn format was causing me problems, until I changed it to doReturn/when.yngwietiger– yngwietiger2015-05-10 03:05:29 +00:00Commented May 10, 2015 at 3:05
- this helped me in particular: "Matcher methods can't be used as return values; there is no way to phrase thenReturn(anyInt()) or thenReturn(any(Foo.class))"cellepo– cellepo2023-08-08 23:40:21 +00:00Commented Aug 8, 2023 at 23:40
- Jeff, this is a fantastic answer, and for me, it's worth returning back to over and over, even though I have a pretty good handle on the topic. I upvoted this answer years ago. But re-reading it, I think there might be a very small error in it. In the second bullet point near the top, you mention that Mockito 2.0+ drops the dependency on Hamcrest. I'm reasonably sure that this change actually happened with Mockito 2.1.0, not 2.0.0. Maybe you'd consider checking this and editing it.Dawood ibn Kareem– Dawood ibn Kareem2023-09-07 07:53:50 +00:00Commented Sep 7, 2023 at 7:53
- @DawoodibnKareem Thank you for the compliment! This one is tricky: Mockito 2.0 went through 111 release candidates but never saw a non-beta release, so publicly 1.10.19 and 2.1.0 are adjacent. That said, the change to a provided dependency is a part of the upgrade to Hamcrest 1.3 in 2.0.26-beta documented in 2.0.24-beta as a 2.0 feature. It's still "2.0+" ("2.0.26-beta+").Jeff Bowman– Jeff Bowman2023-09-07 15:52:08 +00:00Commented Sep 7, 2023 at 15:52
- Oh, wow, OK. I never realised that 2.0 didn't get out of beta. Please accept my apologies for my incorrect "correction".Dawood ibn Kareem– Dawood ibn Kareem2023-09-09 03:29:29 +00:00Commented Sep 9, 2023 at 3:29
Add a comment |
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-java