-
Notifications
You must be signed in to change notification settings - Fork 59
Misc refactor #30
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
Misc refactor #30
Conversation
…ent synthetic methods and smart-nulls mocks
Removes dependency on eager, reflection-based stubbing for default arguments
…e exceptions are always properly handled It also detects un-stubbed invocations
@@ -179,7 +187,8 @@ private[mockito] trait MockitoEnhancer extends MockCreator { | |||
/** | |||
* Delegates to <code>Mockito.withSettings()</code>, it's only here to expose the full Mockito API | |||
*/ | |||
def withSettings: MockSettings = Mockito.withSettings() | |||
def withSettings(implicit defaultAnswer: Answer[_]): MockSettings = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe default this so it can be used without the implicit in scope? also update the doc
@@ -11,45 +12,93 @@ import org.mockito.session.MockitoSessionLogger | |||
import scala.collection.mutable | |||
import scala.collection.JavaConverters._ | |||
|
|||
class MockitoScalaSession(name: String, strictness: Strictness, logger: MockitoSessionLogger) { | |||
private val listener = new IgnoreDefaultArgumentsMockListener | |||
class MockitoScalaSession private (name: String, strictness: Strictness, logger: MockitoSessionLogger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this so people can integrate this using before/after hooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍
README.md
Outdated
``` | ||
That's it! that block of code will execute within a session and will handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will handle what?
@@ -39,34 +41,42 @@ trait IdiomaticMockito extends MockCreator { | |||
when(stubbing) thenAnswer functionToAnswer(f) | |||
|
|||
def shouldAnswer[P0, P1, P2](f: (P0, P1, P2) => T): OngoingStubbing[T] = | |||
when(stubbing) thenAnswer functionToAnswer(f) | |||
when(stubbing) thenAnswer functionToAnswer( | |||
f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny formatting I have to say. Is it scalafmt or sth else causing this?
else | ||
throw new SmartNullPointerException( | ||
s"""You have a NullPointerException because this method call was *not* stubbed correctly: | ||
|[$unStubbedInvocation] on the Mock [${unStubbedInvocation.getMock}]""".stripMargin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE!
classOf[Iterator[_]] -> Iterator.empty, | ||
classOf[Stream[_]] -> Stream.empty, | ||
classOf[Vector[_]] -> Vector.empty, | ||
classOf[Try[_]] -> Failure(new MockitoException("Auto stub provided by mockito-scala")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe Future
as well?
I would also think about making it a bit more extensible, so one could add monix
or cats-io
or other types here as well. OTOH I don't expect people to actually do that as this is something you find very useful when its already there but you don't hit it often enough to put the effort into extending this functionality.
…(if any had happen)
Any default answer handles default parameters
No description provided.