Skip to content

Commit c4bde0f

Browse files
committed
Merge pull request #2 from nhaarman/release-0.1.2
Release 0.1.2
2 parents b40c9ae + 9856798 commit c4bde0f

File tree

9 files changed

+130
-72
lines changed

9 files changed

+130
-72
lines changed

.travis.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,15 @@ install:
1313
- true
1414

1515
script:
16-
- ./gradlew test
16+
- ./gradlew test
17+
18+
before_cache:
19+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
20+
- rm -f $HOME/.gradle/caches/2.10/plugin-resolution/cache.properties.lock
21+
- rm -f $HOME/.gradle/caches/2.10/plugin-resolution/cache.properties
22+
cache:
23+
directories:
24+
- $HOME/.gradle/caches
25+
- $HOME/.gradle/daemon
26+
- $HOME/.gradle/native
27+
- $HOME/.gradle/wrapper

mockito-kotlin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bintray {
4949
name = "Mockito-Kotlin"
5050
desc = "Using Mockito with Kotlin"
5151

52-
licenses = ['Apache-2.0']
52+
licenses = ['MIT']
5353
vcsUrl = 'https://github.com/bintray/gradle-bintray-plugin.git'
5454

5555
version {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package com.nhaarman.mockito_kotlin
2727

2828
import org.mockito.Mockito
2929
import org.mockito.verification.VerificationMode
30+
import kotlin.reflect.KClass
3031

3132
inline fun <reified T : Any> mock() = Mockito.mock(T::class.java)
3233
fun <T : Any> spy(value: T) = Mockito.spy(value)
@@ -40,6 +41,7 @@ fun <T> reset(mock: T) = Mockito.reset(mock)
4041
fun inOrder(vararg value: Any) = Mockito.inOrder(*value)
4142
fun never() = Mockito.never()
4243

43-
fun <T> eq(value: T) = Mockito.eq(value)
44+
inline fun <reified T : Any> eq(value: T) = eq(value, T::class)
45+
fun <T : Any> eq(value: T, kClass: KClass<T>) = Mockito.eq(value) ?: createInstance(kClass)
4446

4547
inline fun <reified T : Any> isNull(): T? = Mockito.isNull(T::class.java)

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

-21
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ import org.junit.Before
3232
import org.junit.Test
3333
import org.mockito.Mockito
3434

35-
/*
36-
* Copyright 2016 Niek Haarman
37-
*
38-
* Licensed under the Apache License, Version 2.0 (the "License");
39-
* you may not use this file except in compliance with the License.
40-
* You may obtain a copy of the License at
41-
*
42-
* http://www.apache.org/licenses/LICENSE-2.0
43-
*
44-
* Unless required by applicable law or agreed to in writing, software
45-
* distributed under the License is distributed on an "AS IS" BASIS,
46-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47-
* See the License for the specific language governing permissions and
48-
* limitations under the License.
49-
*/
50-
5135
class AnyTest {
5236

5337
private lateinit var doAnswer: Fake
@@ -385,11 +369,6 @@ class AnyTest {
385369
expect(result).toBe(MyEnum.VALUE)
386370
}
387371

388-
open class Fake {
389-
open fun go(arg: Any?) {
390-
}
391-
}
392-
393372
class ClosedClass
394373
class ClosedParameterizedClass(val fake: Fake)
395374
class ClosedClosedParameterizedClass(val closed: ClosedParameterizedClass)
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2016 Niek Haarman
5+
* Copyright (c) 2007 Mockito contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
import com.nhaarman.expect.expect
27+
import com.nhaarman.mockito_kotlin.eq
28+
import com.nhaarman.mockito_kotlin.mock
29+
import org.junit.After
30+
import org.junit.Before
31+
import org.junit.Test
32+
import org.mockito.Mockito
33+
34+
class EqTest {
35+
36+
private val interfaceInstance: MyInterface = MyClass()
37+
private val openClassInstance: MyClass = MyClass()
38+
private val closedClassInstance: ClosedClass = ClosedClass()
39+
40+
private lateinit var doAnswer: Fake
41+
42+
@Before
43+
fun setup() {
44+
/* Create a proper Mockito state */
45+
doAnswer = Mockito.doAnswer { }.`when`(mock())
46+
}
47+
48+
@After
49+
fun tearDown() {
50+
/* Close `any` Mockito state */
51+
doAnswer.go(0)
52+
}
53+
54+
@Test
55+
fun eqInterfaceInstance() {
56+
/* When */
57+
val result = eq(interfaceInstance)
58+
59+
/* Then */
60+
expect(result).toNotBeNull()
61+
}
62+
63+
@Test
64+
fun eqOpenClassInstance() {
65+
/* When */
66+
val result = eq(openClassInstance)
67+
68+
/* Then */
69+
expect(result).toNotBeNull()
70+
}
71+
72+
@Test
73+
fun eqClosedClassInstance() {
74+
/* When */
75+
val result = eq(closedClassInstance)
76+
77+
/* Then */
78+
expect(result).toNotBeNull()
79+
}
80+
81+
private interface MyInterface
82+
private open class MyClass : MyInterface
83+
class ClosedClass
84+
}
85+
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2016 Niek Haarman
5+
* Copyright (c) 2007 Mockito contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
open class Fake {
27+
open fun go(arg: Any?) {
28+
}
29+
}

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

-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ import com.nhaarman.mockito_kotlin.mock
2828
import com.nhaarman.mockito_kotlin.verify
2929
import org.junit.Test
3030

31-
/*
32-
* Copyright 2016 Niek Haarman
33-
*
34-
* Licensed under the Apache License, Version 2.0 (the "License");
35-
* you may not use this file except in compliance with the License.
36-
* You may obtain a copy of the License at
37-
*
38-
* http://www.apache.org/licenses/LICENSE-2.0
39-
*
40-
* Unless required by applicable law or agreed to in writing, software
41-
* distributed under the License is distributed on an "AS IS" BASIS,
42-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43-
* See the License for the specific language governing permissions and
44-
* limitations under the License.
45-
*/
46-
4731
class MatcherTest {
4832

4933
@Test

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

-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ import com.nhaarman.mockito_kotlin.mock
2828
import org.junit.Test
2929
import org.mockito.exceptions.base.MockitoException
3030

31-
/*
32-
* Copyright 2016 Niek Haarman
33-
*
34-
* Licensed under the Apache License, Version 2.0 (the "License");
35-
* you may not use this file except in compliance with the License.
36-
* You may obtain a copy of the License at
37-
*
38-
* http://www.apache.org/licenses/LICENSE-2.0
39-
*
40-
* Unless required by applicable law or agreed to in writing, software
41-
* distributed under the License is distributed on an "AS IS" BASIS,
42-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43-
* See the License for the specific language governing permissions and
44-
* limitations under the License.
45-
*/
46-
4731
class MockTest {
4832

4933
private lateinit var propertyInterfaceVariable: MyInterface

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

-16
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,6 @@
2323
* THE SOFTWARE.
2424
*/
2525

26-
/*
27-
* Copyright 2016 Niek Haarman
28-
*
29-
* Licensed under the Apache License, Version 2.0 (the "License");
30-
* you may not use this file except in compliance with the License.
31-
* You may obtain a copy of the License at
32-
*
33-
* http://www.apache.org/licenses/LICENSE-2.0
34-
*
35-
* Unless required by applicable law or agreed to in writing, software
36-
* distributed under the License is distributed on an "AS IS" BASIS,
37-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38-
* See the License for the specific language governing permissions and
39-
* limitations under the License.
40-
*/
41-
4226
import com.nhaarman.expect.expect
4327
import com.nhaarman.mockito_kotlin.spy
4428
import org.junit.Test

0 commit comments

Comments
 (0)