You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-88Lines changed: 17 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,96 +17,25 @@ dependencies {
17
17
}
18
18
```
19
19
20
-
## Examples
20
+
## Example
21
21
22
-
### Creating mock instances
23
-
24
-
Due to Kotlin's [reified type parameters](https://kotlinlang.org/docs/reference/inline-functions.html#reified-type-parameters), if the type can be inferred, you don't have to specify it explicitly:
25
-
26
-
**Java**:
27
-
```java
28
-
MyClass c = mock(Myclass.class);
29
-
c.doSomething(mock(MyOtherClass.class));
30
-
```
31
-
32
-
**Kotlin**:
33
-
```kotlin
34
-
val c :MyClass= mock()
35
-
c.doSomething(mock())
36
-
```
37
-
38
-
If the type can't be inferred, you can pass it like so:
39
-
40
-
```kotlin
41
-
val d = mock<MyClass>()
42
-
```
43
-
44
-
45
-
### Expecting any value
46
-
47
-
Mockito's `any(Class<T>)` often returns `null` for non-primitive classes.
48
-
In Kotlin, this can be a problem due to its [null-safety](https://kotlinlang.org/docs/reference/null-safety.html) feature.
49
-
This library creates non-null instances when necessary.
50
-
Again, if the type can be inferred, you don't have to specify it explicitely:
51
-
52
-
**Java**:
53
-
```java
54
-
verify(myClass).doSomething(any(String.class));
55
-
```
56
-
57
-
**Kotlin**:
58
-
```kotlin
59
-
verify(myClass).doSomething(any()); // Non-nullable parameter type is inferred
60
-
```
61
-
62
-
For generic arrays, use the `anyArray()` method:
63
-
64
-
```kotlin
65
-
verify(myClass).setItems(anyArray())
66
-
```
67
-
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:
0 commit comments