-
Notifications
You must be signed in to change notification settings - Fork 202
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
Easy way to make a mock with settings #148
Comments
Can you give an example of how you would use it in Java? |
Sure, here it is in Kotlin. Mostly it's that
|
Ah, so if I understand correctly you'd want some syntax like the following?
|
Exactly. Is that reasonable? |
Sounds valid. Perhaps something can be done with a parameter with a default value. I'll have a look later on! |
mock
with settings
The fun withSettings(
extraInterfaces: Array<KClass<Any>>? = null,
name: String? = null,
spiedInstance: Any? = null,
defaultAnswer: Answer<Any>? = null,
serializable: Boolean = false,
serializableMode: SerializableMode? = null,
verboseLogging: Boolean = false,
invocationListeners: Array<InvocationListener>? = null,
stubOnly: Boolean = false,
@Incubating useConstructor: Boolean = false,
@Incubating outerInstance: Any? = null
): MockSettings This will not break current code as they will all use the default values. -inline fun <reified T : Any> mock(): T
+inline fun <reified T : Any> mock(
+ extraInterfaces: Array<KClass<Any>>? = null,
+ name: String? = null,
+ spiedInstance: Any? = null,
+ defaultAnswer: Answer<Any>? = null,
+ serializable: Boolean = false,
+ serializableMode: SerializableMode? = null,
+ verboseLogging: Boolean = false,
+ invocationListeners: Array<InvocationListener>? = null,
+ stubOnly: Boolean = false,
+ @Incubating useConstructor: Boolean = false,
+ @Incubating outerInstance: Any? = null
+): T Usage would be intuitive: val myMock = mock<MyClass>(
name = "Custom name",
verboseLogging = true
) The same can be done for the stubbing variant: val myMock = mock<MyClass>(
name = "Custom name",
verboseLogging = true
) {
on { doSomething() } doReturn true
} If this is introduced, we can deprecate the other What do you think? |
That looks awesome. Thanks for the quick turnaround! |
Great! I'll do some field tests tomorrow and draft a release in the coming week probably. |
Is there an easy way to include
MockSettings
(in particular,RETURNS_DEEP_STUBS
) using this syntax? It seems like you can either use this or this but not both.Thanks!
The text was updated successfully, but these errors were encountered: