Skip to content

Commit 17dadf9

Browse files
committed
Update README.md
1 parent cddcf7f commit 17dadf9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ For generic arrays, use the `anyArray()` method:
6565
verify(myClass).setItems(anyArray())
6666
```
6767

68+
## Custom instance creators
69+
70+
There are some cases where Mockito-Kotlin cannot create an instance of a class.
71+
This can for instance be when a constructor has some specific preconditions
72+
for its parameters.
73+
You can _register_ `instance creators` to overcome this:
74+
75+
```kotlin
76+
MockitoKotlin.registerInstanceCreator<MyClass> { MyClass(5) }
77+
```
78+
79+
Whenever MockitoKotlin needs to create an instance of `MyClass`, this function is called,
80+
giving you ultimate control over how these instances are created.
81+
6882
### Argument Matchers
6983

7084
Using higher-order functions, you can write very clear expectations about expected values.

0 commit comments

Comments
 (0)