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

Introduce "expect (...) ON x" to be used instead of "expect (...) TO x" on mock objects #220

Merged
merged 3 commits into from
Apr 6, 2020

Conversation

einholen
Copy link
Contributor

@einholen einholen commented Apr 6, 2020

Resolves #212 for Expect DSL

Comment on lines +11 to +13
if (c.settings.contains("mockito-print-expect")) {
val pos = s"${c.enclosingPosition.source.file.name}:${c.enclosingPosition.line}"
println(pos + " " + show(r.tree))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, we should extract a function and use it everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a separate PR: #221

The two PRs will conflict with each other once merged, I'll resolve whichever comes last

Comment on lines 25 to 35
q"""if (!_root_.org.mockito.MockitoSugar.mockingDetails($obj).isMock)
throw new _root_.org.mockito.exceptions.misusing.MissingMethodInvocationException(Seq(
"'expect no calls to <?>' requires an argument which is 'a method call on a mock',",
" but [" + $calledPattern + "] is a mock object.",
"",
"The following would be correct (note the usage of 'calls to' vs 'calls on'):",
" expect no calls to " + $calledPattern + ".bar(*)",
" expect no calls on " + $calledPattern,
""
).mkString("\n"))
else ${transformInvocation(c)(q"$obj.$methodOrField", order, q"${c.prefix}.mode")}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, the postfix verification currently uses the standard mockito exception, but I like this one with more info, should be extracted

Comment on lines 76 to 83
exception.getMessage shouldBe
"""'expect no calls to <?>' requires an argument which is 'a method call on a mock',
| but [fixture.org] is a mock object.
|
|The following would be correct (note the usage of 'calls to' vs 'calls on'):
| expect no calls to fixture.org.bar(*)
| expect no calls on fixture.org
|""".stripMargin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@ultrasecreth ultrasecreth merged commit 421cb68 into mockito:release/1.x Apr 6, 2020
@einholen einholen deleted the expect-no-calls-on branch April 6, 2020 13:50
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.

"aMock wasNever called" treats mocks defined inside fixture objects as method calls
2 participants