Skip to content

Commit 17056aa

Browse files
authored
Merge pull request #141 from nhaarman/argwhere
Add argWhere function
2 parents 8380e14 + 4d6c490 commit 17056aa

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean) = Mock
6868
*/
6969
inline fun <reified T : Any> argForWhich(noinline predicate: T.() -> Boolean) = argThat(predicate)
7070

71+
/**
72+
* Creates a custom argument matcher.
73+
* `null` values will never evaluate to `true`.
74+
*
75+
* @param predicate A function that returns `true` when given [T] matches the predicate.
76+
*/
77+
inline fun <reified T: Any> argWhere(noinline predicate: (T) -> Boolean) = argThat(predicate)
78+
7179
/**
7280
* For usage with verification only.
7381
*

mockito-kotlin/src/test/kotlin/test/MockitoTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ class MockitoTest : TestBase() {
128128
}
129129
}
130130

131+
@Test
132+
fun listArgWhere() {
133+
mock<Methods>().apply {
134+
closedList(listOf(Closed(), Closed()))
135+
verify(this).closedList(argWhere {
136+
it.size == 2
137+
})
138+
}
139+
}
140+
131141
@Test
132142
fun listArgCheck() {
133143
mock<Methods>().apply {

tmp.txt

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
a1ea33b Update Dokka to 0.9.11
2+
e3344f4 Update Gradle wrapper to 3.2.1
3+
3c714eb Update Kotlin to 1.0.5-3
4+
8118f1a Update Mockito to 2.3.9
5+
327d431 Merge pull request #137 from nhaarman/release-1.0.1
6+
8c9e5d7 Merge branch 'master' into dev
7+
e07e419 Update PULL_REQUEST_TEMPLATE.md
8+
263344f Merge pull request #135 from nhaarman/handle-null-in-argumentmatcher
9+
b77d969 Handle `null` in argument matchers.
10+
543238f Merge pull request #131 from nhaarman/release-1.0.0
11+
ed6d30d Update tagging script
12+
af1940c Update Mockito to 2.2.28
13+
0ba47f4 Update dokka plugin
14+
04cd24d Merge pull request #130 from nhaarman/release-1.0.0-RC1
15+
5418cff Update README.md
16+
559ffc5 Remove deprecated methods
17+
dc4ab0a Update publishing
18+
a734cde Test with Kotlin 1.1-M03
19+
7fb4bd9 Merge pull request #127 from nhaarman/release-0.12.2
20+
05a65ec Update Mockito to 2.2.22
21+
62f3170 Merge branch 'ghostbuster91-FeatureRequest_isAclassShouldReturnInstance' into dev
22+
acde82f Change isA method to return instance of T
23+
72279be Merge pull request #123 from nhaarman/release-0.12.1
24+
c974db0 Update Mockito to 2.2.17
25+
e6f6d2c Update Kotlin to 1.0.5-2
26+
b665264 Merge pull request #122 from nhaarman/inorder-lambda
27+
59bf311 Add a lambda to inOrder() for easier verification
28+
b50831b Fix release build config
29+
ebc6147 Merge pull request #121 from nhaarman/release-0.12.0
30+
66d8249 Also test with Kotlin 1.1
31+
cdc34a0 Merge pull request #120 from nhaarman/cast-null
32+
18ed580 Use `null as T` to create instances
33+
ae1d863 Merge pull request #119 from nhaarman/clean-tests
34+
ab1eb0d Use same test source for inline tests
35+
2b31ed7 Merge branch 'master' into dev
36+
57d0d8b Merge pull request #118 from nhaarman/improve-argumentcaptor
37+
81a0996 Add value shortcuts to ArgumentCaptor
38+
37f1717 Merge pull request #117 from nhaarman/nullable-eq
39+
1eead3e Return passed value instead of trying to create an instance
40+
a831657 Update Mockito to 2.2.15
41+
5f12032 Merge pull request #113 from rongi/patch-1
42+
e7ed7cb Update to Kotlin 1.0.5
43+
27c6bf6 Merge pull request #111 from nhaarman/release-0.11.0
44+
771f761 Merge pull request #110 from nhaarman/graciously_fail
45+
c8fecf0 Try to use constructor when mocking fails
46+
fa27978 Merge pull request #109 from nhaarman/nullable-mockstubbing
47+
f353562 Accept nullable return types when stubbing
48+
50a1b91 Merge pull request #108 from nhaarman/release-0.10.1
49+
c3f7e68 Merge pull request #107 from nhaarman/create-primitive-instance
50+
0615231 Don't try to mock primitive/wrapper instances
51+
494e7ca Merge pull request #105 from nhaarman/fix-generic-returntype-npe
52+
113d9e9 Catch an NPE thrown by the Kotlin type checker in the Mockito library.
53+
3b5c40a Merge pull request #102 from nhaarman/release-0.10.0
54+
6af0904 Update Mockito to 2.2.9
55+
287065a Merge pull request #101 from nhaarman/skip-optional-parameters
56+
42cee20 Don't count optional parameters when trying to find an easy constructor
57+
e43ccea Merge pull request #100 from nhaarman/nullable-argumentcaptor
58+
086d482 Add `nullableArgumentCaptor` to be able to work with lists of nullables
59+
7b6c5b7 Merge branch 'desilvai-dev' into dev
60+
395e578 Fixed infinite loop caused by 'copy constructors' invoked by createInstance. The fix is to skip all constructors that take in parameters with same type as the object we are trying to build.
61+
24108bd Merge pull request #98 from nhaarman/release-0.9.0
62+
6126454 Update version badge
63+
5a31910 Merge pull request #97 from nhaarman/deprecation-levels
64+
63826bf Upgrade deprecation levels to ERROR
65+
3db9e21 Update Mockito to 2.2.6
66+
5884adc Merge pull request #96 from nhaarman/dokka
67+
fb74552 Use dokka do generate docs
68+
f165976 Merge pull request #95 from nhaarman/publish-to-maven-central
69+
8e083ad Publish to Maven Central instead of Bintray
70+
5878bbe Merge pull request #93 from nhaarman/release-0.8.0
71+
d556691 Update Mockito to 2.2.1
72+
6ee75f7 Merge pull request #92 from nhaarman/create-array-instance
73+
0b43d0b Use the java class' name to create an array instance
74+
cd16b04 Merge pull request #91 from nhaarman/improve-captors
75+
80dbefd Improve argument captors
76+
fd98501 Merge pull request #90 from nhaarman/ongoingstubbing-dothrow
77+
94b3c65 Added doThrow methods to OngoingStubbing
78+
85bb5e4 Merge branch 'desilvai-dev' into dev
79+
6965414 Fix compatibility with mock-maker-inline for mocking final classes
80+
ea6e64c Merge pull request #85 from nhaarman/release-0.7.0
81+
36e3dd5 Merge pull request #84 from nhaarman/fix-createinstance-from-lambda
82+
1d65fc0 Strip methods from file identifiers.
83+
1025568 Merge pull request #83 from nhaarman/stubbing-mock-reference
84+
0c3e137 Provide mock instance to stubbing method in mock()
85+
3f73e27 Merge pull request #82 from nhaarman/mockito-rc2
86+
e549d8d Update Mockito dependency to 2.1.0
87+
0886485 Update Mockito dependency to RC2
88+
2d724bc Merge pull request #74 from viniciussoares/dev
89+
f2ed004 Upgrade Kotlin to 1.0.4.
90+
9c4234e Merge pull request #73 from nhaarman/release-0.6.2
91+
cf06555 Merge pull request #72 from nhaarman/any-or-null
92+
9351840 Include `anyOrNull()`
93+
3d64888 Merge pull request #71 from jpshelley/mockito-2.1.0-RC.1
94+
6862ea5 update to RC.1
95+
4c09ebc Merge branch 'master' into dev
96+
f18d86e Merge pull request #70 from nhaarman/release-0.6.1
97+
650e293 Update README.md
98+
f291e71 Merge pull request #69 from nhaarman/argforwhich
99+
9a3b7de Introduce argForWhich() as an alias for argThat()
100+
8d53bad Merge pull request #68 from nhaarman/fix-anyarrayofnullables
101+
9507a20 Make anyArray() accept nullable types.
102+
7dcebc9 Stop. Sending me. Emails.
103+
c029a13 Merge pull request #67 from nhaarman/deprecate-deprecated-methods
104+
400b1cc Deprecate methods that are deprecated in Mockito.
105+
c06d37f Merge pull request #64 from nhaarman/fix-simplest-constructor
106+
18be968 Improve `easiestConstructor()` to sort by parameters size.
107+
855c14b Update gradle wrapper to 3.0
108+
58013d8 Update dependencies
109+
6110a90 Update Mockito version to 2.1.0-beta.125
110+
6cf8557 Update README.md
111+
d07a2c9 Merge pull request #59 from nhaarman/release-0.6.0
112+
2a2ed98 Merge pull request #58 from nhaarman/mock-stubbing
113+
ecfaf58 Add infix modifiers to doReturn methods
114+
2d4eef9 Accept a stubbing lambda in mock()
115+
84fb7e0 Merge branch 'master' into dev
116+
49d59a6 Merge pull request #55 from sghill/mockito-2.0.99-beta
117+
2f94f52 Upgrade Mockito to 2.0.99-beta
118+
a6f8604 Merge pull request #53 from nhaarman/release-0.5.2
119+
51385ca Added an example to the Readme on Argument Captors.
120+
6a521ea Make `doReturn` accept null values.
121+
c3e6182 Specify explicit return types for Mockito calls.
122+
6867394 Merge pull request #50 from Zoltu/patch-1
123+
25fb19c Upgrade Kotlin version to 1.0.3.
124+
e1de1f6 Makes `mock` return non-null types.
125+
bb4ac76 Merge pull request #43 from nhaarman/release-0.5.1
126+
8e6ab15 Update gradle wrapper version
127+
c400381 Merge pull request #42 from hamen/master
128+
c44c15a Update Kotlin version
129+
62cd94f Merge pull request #38 from nhaarman/release-0.5.0
130+
aa49bde Merge pull request #23 from nhaarman/instance-creators
131+
f765a31 Use instance creators only from single test file.
132+
17dadf9 Update README.md
133+
cddcf7f Introduce instance creators.
134+
4cbd876 Merge pull request #36 from nhaarman/release-0.4.1
135+
abfc083 Update dependencies
136+
772d0d9 Merge pull request #33 from nhaarman/release-0.4.0
137+
1322b92 Update dependencies
138+
55e9a3c Merge pull request #30 from nhaarman/release-0.3.1
139+
df0c3f6 Remove Travis-CI cache
140+
d4e73a9 Merge pull request #29 from nhaarman/uncheckedmock-interceptor
141+
c8d9f68 Unset the MockitoInterceptor for unchecked mocks.
142+
129f9e6 Merge pull request #28 from nhaarman/create-class-objects
143+
ae4ab17 Account for Class<T> when creating instances.
144+
a013a48 Merge pull request #19 from nhaarman/avoid-array-parameters
145+
ea0263d Avoid constructors with an array as a parameter.
146+
48fc1aa Merge pull request #16 from nhaarman/release-0.3.0
147+
fc95068 Merge branch 'dev' of https://github.com/codeborne/mockito-kotlin into codeborne-dev
148+
5105493 Include more static Mockito methods
149+
9238c4c add simpler capture() method with lambda
150+
ce93783 Merge pull request #12 from codeborne/master
151+
66e3be5 add simplified ArgumentCaptor support
152+
1262c19 add deep stubs test
153+
f6f142a add spy stubbing tests
154+
0efd093 Added PR template
155+
624b7c4 Merge pull request #10 from ViFork/master
156+
334d471 add missing imports
157+
76be5d0 add more missing Mockito methods, especially to be used with spies
158+
40bf7c6 changed kotlin version to 1.0.0
159+
7cafd23 Merge pull request #7 from nhaarman/release-0.2.0
160+
8b93c66 Update Kotlin to rc-1036
161+
8488479 Merge pull request #6 from nhaarman/release-0.1.6
162+
1d9a588 Use smallest constructor
163+
37ded6f Merge pull request #5 from nhaarman/release-0.1.5
164+
8157be6 Support Boolean
165+
0665c25 Merge pull request #4 from nhaarman/release-0.1.4
166+
a873fa7 Support private classes
167+
0cc78ba Merge pull request #3 from nhaarman/release-0.1.3
168+
65d6a5f Support object instances
169+
c4bde0f Merge pull request #2 from nhaarman/release-0.1.2
170+
9856798 Proper license
171+
9f1df2d Make sure 'eq' does not return null
172+
90f6598 Merge branch 'master' into dev
173+
b40c9ae Update README.md
174+
ad964f7 Update README.md
175+
92bb350 Cache Travis dependencies
176+
886cad6 Proper version names
177+
139d47c Proper version names
178+
78505b7 Merge pull request #1 from nhaarman/release-0.1.1
179+
b5a4e87 Support enums
180+
b113029 Upload to Bintray
181+
2f9603a Initial commit

0 commit comments

Comments
 (0)