From a873fa74104885e25244572c9709a6b55bd3bf0f Mon Sep 17 00:00:00 2001 From: Niek Haarman Date: Sun, 24 Jan 2016 20:45:30 +0100 Subject: [PATCH] Support private classes --- mockito-kotlin/build.gradle | 2 +- .../kotlin/com/nhaarman/mockito_kotlin/Any.kt | 148 --------------- .../nhaarman/mockito_kotlin/CreateInstance.kt | 134 +++++++++++++ .../mockito_kotlin/MatcherExtension.kt | 38 ---- .../com/nhaarman/mockito_kotlin/Mockito.kt | 12 +- .../{AnyTest.kt => CreateInstanceTest.kt} | 179 ++++++++---------- mockito-kotlin/src/test/kotlin/SpyTest.kt | 8 + 7 files changed, 233 insertions(+), 288 deletions(-) delete mode 100644 mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Any.kt create mode 100644 mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/CreateInstance.kt delete mode 100644 mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/MatcherExtension.kt rename mockito-kotlin/src/test/kotlin/{AnyTest.kt => CreateInstanceTest.kt} (65%) diff --git a/mockito-kotlin/build.gradle b/mockito-kotlin/build.gradle index acfa7736..1b28258c 100644 --- a/mockito-kotlin/build.gradle +++ b/mockito-kotlin/build.gradle @@ -68,4 +68,4 @@ task javadocJar(type: Jar, dependsOn: javadoc) { task sourcesJar(type: Jar) { from sourceSets.main.allSource classifier = 'sources' -} \ No newline at end of file +} diff --git a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Any.kt b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Any.kt deleted file mode 100644 index 84420d64..00000000 --- a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Any.kt +++ /dev/null @@ -1,148 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2016 Niek Haarman - * Copyright (c) 2007 Mockito contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.nhaarman.mockito_kotlin - -import org.mockito.Answers -import org.mockito.Mockito -import org.mockito.internal.creation.MockSettingsImpl -import org.mockito.internal.util.MockUtil -import java.lang.reflect.Modifier -import java.lang.reflect.ParameterizedType -import java.lang.reflect.Type -import kotlin.reflect.KClass -import kotlin.reflect.KType -import kotlin.reflect.defaultType -import kotlin.reflect.jvm.javaType - -inline fun anyArray(): Array = Mockito.any(Array::class.java) ?: arrayOf() -inline fun any() = any(T::class) -fun any(clzz: KClass) = Mockito.any(clzz.java) ?: createInstance(clzz) - -internal fun createInstance(kClass: KClass): T { - return createInstance(kClass.defaultType) as T -} - -@Suppress("UNCHECKED_CAST") -private fun createInstance(kType: KType): T? { - if (kType.isMarkedNullable) { - return null - } - - val javaType: Type = kType.javaType - if (javaType is ParameterizedType) { - val rawType = javaType.rawType - return createInstance(rawType as Class) - } else if (javaType is Class<*> && javaType.isPrimitive) { - return defaultPrimitive(javaType as Class) - } else if (javaType is Class<*>) { - return createInstance(javaType as Class) - } else { - return null - } -} - -@Suppress("UNCHECKED_CAST") -private fun createInstance(jClass: Class): T { - if (!Modifier.isFinal(jClass.modifiers)) { - return uncheckedMock(jClass) - } - - if (jClass.isPrimitive || jClass == String::class.java) { - return defaultPrimitive(jClass) - } - - if (jClass.isEnum) { - return jClass.enumConstants.first() - } - - if (jClass.isArray) { - return jClass.toArrayInstance() - } - - jClass.kotlin.objectInstance?.let { - return it - } - - val constructor = jClass.constructors - .sortedBy { it.parameterTypes.size } - .first() - - val params = constructor.parameterTypes.map { createInstance(it) } - - val result: Any = when (params.size) { - 0 -> constructor.newInstance() - 1 -> constructor.newInstance(params[0]) - 2 -> constructor.newInstance(params[0], params[1]) - 3 -> constructor.newInstance(params[0], params[1], params[2]) - 4 -> constructor.newInstance(params[0], params[1], params[2], params[3]) - 5 -> constructor.newInstance(params[0], params[1], params[2], params[3], params[4]) - 6 -> constructor.newInstance(params[0], params[1], params[2], params[3], params[4], params[5]) - 7 -> constructor.newInstance(params[0], params[1], params[2], params[3], params[4], params[5], params[6]) - 8 -> constructor.newInstance(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7]) - 9 -> constructor.newInstance(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8]) - 10 -> constructor.newInstance(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8], params[9]) - else -> throw UnsupportedOperationException("Cannot create a new instance for ${jClass.canonicalName} with ${params.size} constructor parameters.") - } - - return result as T -} - -@Suppress("UNCHECKED_CAST", "IMPLICIT_CAST_TO_UNIT_OR_ANY") -private fun defaultPrimitive(clzz: Class): T { - return when (clzz.canonicalName) { - "byte" -> 0.toByte() - "short" -> 0.toShort() - "int" -> 0 - "double" -> 0.0 - "float" -> 0f - "long" -> 0 - "java.lang.String" -> "" - else -> throw UnsupportedOperationException("Cannot create default primitive for ${clzz.canonicalName}.") - } as T -} - -/** - * Creates a mock instance of given class, without modifying or checking any internal Mockito state. - */ -@Suppress("UNCHECKED_CAST") -private fun uncheckedMock(clzz: Class): T { - val impl = MockSettingsImpl().defaultAnswer(Answers.RETURNS_DEFAULTS) as MockSettingsImpl<*> - val creationSettings = impl.confirm(clzz) - return MockUtil().createMock(creationSettings) as T -} - -@Suppress("UNCHECKED_CAST", "IMPLICIT_CAST_TO_UNIT_OR_ANY") -private fun Class.toArrayInstance(): T { - return when (simpleName) { - "byte[]" -> byteArrayOf() - "short[]" -> shortArrayOf() - "int[]" -> intArrayOf() - "long[]" -> longArrayOf() - "double[]" -> doubleArrayOf() - "float[]" -> floatArrayOf() - else -> throw UnsupportedOperationException("Cannot create a generic array for $simpleName. Use anyArray() instead.") - } as T -} diff --git a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/CreateInstance.kt b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/CreateInstance.kt new file mode 100644 index 00000000..f2abb61f --- /dev/null +++ b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/CreateInstance.kt @@ -0,0 +1,134 @@ +/* + * The MIT License + * + * Copyright (c) 2016 Niek Haarman + * Copyright (c) 2007 Mockito contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.nhaarman.mockito_kotlin + +import org.mockito.Answers +import org.mockito.internal.creation.MockSettingsImpl +import org.mockito.internal.util.MockUtil +import java.lang.reflect.Modifier +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type +import kotlin.reflect.KClass +import kotlin.reflect.KFunction +import kotlin.reflect.KType +import kotlin.reflect.defaultType +import kotlin.reflect.jvm.isAccessible +import kotlin.reflect.jvm.javaType + +/** + * A collection of functions that tries to create an instance of + * classes to avoid NPE's when using Mockito with Kotlin. + */ + +inline fun createArrayInstance() = arrayOf() + +inline fun createInstance() = createInstance(T::class) + +fun createInstance(kClass: KClass): T { + return when { + kClass.hasObjectInstance() -> kClass.objectInstance!! + kClass.isMockable() -> kClass.java.uncheckedMock() + kClass.isPrimitive() -> kClass.toDefaultPrimitiveValue() + kClass.isEnum() -> kClass.java.enumConstants.first() + kClass.isArray() -> kClass.toArrayInstance() + else -> kClass.constructors.first().newInstance() + } +} + +@Suppress("SENSELESS_COMPARISON") +private fun KClass<*>.hasObjectInstance() = objectInstance != null + +private fun KClass<*>.isMockable() = !Modifier.isFinal(java.modifiers) +private fun KClass<*>.isEnum() = java.isEnum +private fun KClass<*>.isArray() = java.isArray +private fun KClass<*>.isPrimitive() = + java.isPrimitive || !defaultType.isMarkedNullable && simpleName in arrayOf( + "Byte", + "Short", + "Int", + "Double", + "Float", + "Long", + "String" + ) + +@Suppress("UNCHECKED_CAST", "IMPLICIT_CAST_TO_UNIT_OR_ANY") +private fun KClass.toDefaultPrimitiveValue(): T { + return when (simpleName) { + "Byte" -> 0.toByte() + "Short" -> 0.toShort() + "Int" -> 0 + "Double" -> 0.0 + "Float" -> 0f + "Long" -> 0 + "String" -> "" + else -> throw UnsupportedOperationException("Cannot create default primitive for $simpleName.") + } as T +} + +@Suppress("UNCHECKED_CAST", "IMPLICIT_CAST_TO_UNIT_OR_ANY") +private fun KClass.toArrayInstance(): T { + return when (simpleName) { + "ByteArray" -> byteArrayOf() + "ShortArray" -> shortArrayOf() + "IntArray" -> intArrayOf() + "LongArray" -> longArrayOf() + "DoubleArray" -> doubleArrayOf() + "FloatArray" -> floatArrayOf() + else -> throw UnsupportedOperationException("Cannot create a generic array for $simpleName. Use createArrayInstance() instead.") + } as T +} + +private fun KFunction.newInstance(): T { + isAccessible = true + return callBy(parameters.toMap { + it to it.type.createNullableInstance() + }) +} + +@Suppress("UNCHECKED_CAST") +private fun KType.createNullableInstance(): T? { + if (isMarkedNullable) { + return null + } + + val javaType: Type = javaType + return when (javaType) { + is ParameterizedType -> (javaType.rawType as Class).uncheckedMock() + is Class<*> -> createInstance((javaType as Class).kotlin) + else -> null + } +} + +/** + * Creates a mock instance of given class, without modifying or checking any internal Mockito state. + */ +@Suppress("UNCHECKED_CAST") +private fun Class.uncheckedMock(): T { + val impl = MockSettingsImpl().defaultAnswer(Answers.RETURNS_DEFAULTS) as MockSettingsImpl<*> + val creationSettings = impl.confirm(this) + return MockUtil().createMock(creationSettings) as T +} diff --git a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/MatcherExtension.kt b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/MatcherExtension.kt deleted file mode 100644 index 041c7c28..00000000 --- a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/MatcherExtension.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2016 Niek Haarman - * Copyright (c) 2007 Mockito contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.nhaarman.mockito_kotlin - -import org.mockito.Mockito -import kotlin.reflect.KClass - -inline fun argThat(noinline predicate: T.() -> Boolean): T { - return argThat(T::class, predicate) -} - -@Suppress("UNCHECKED_CAST") -fun argThat(kClass: KClass, predicate: T.() -> Boolean): T { - return Mockito.argThat { it -> (it as T).predicate() } ?: createInstance(kClass) -} diff --git a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt index b3e77d60..3d093230 100644 --- a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt +++ b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt @@ -41,7 +41,13 @@ fun reset(mock: T) = Mockito.reset(mock) fun inOrder(vararg value: Any) = Mockito.inOrder(*value) fun never() = Mockito.never() -inline fun eq(value: T) = eq(value, T::class) -fun eq(value: T, kClass: KClass) = Mockito.eq(value) ?: createInstance(kClass) - +inline fun eq(value: T) = Mockito.eq(value) ?: createInstance() +inline fun anyArray(): Array = Mockito.any(Array::class.java) ?: arrayOf() +inline fun any() = Mockito.any(T::class.java) ?: createInstance() inline fun isNull(): T? = Mockito.isNull(T::class.java) + +inline fun argThat(noinline predicate: T.() -> Boolean) = argThat(T::class, predicate) + +@Suppress("UNCHECKED_CAST") +fun argThat(kClass: KClass, predicate: T.() -> Boolean) + = Mockito.argThat { it -> (it as T).predicate() } ?: createInstance(kClass) diff --git a/mockito-kotlin/src/test/kotlin/AnyTest.kt b/mockito-kotlin/src/test/kotlin/CreateInstanceTest.kt similarity index 65% rename from mockito-kotlin/src/test/kotlin/AnyTest.kt rename to mockito-kotlin/src/test/kotlin/CreateInstanceTest.kt index f2d056b6..d2ea5682 100644 --- a/mockito-kotlin/src/test/kotlin/AnyTest.kt +++ b/mockito-kotlin/src/test/kotlin/CreateInstanceTest.kt @@ -24,360 +24,343 @@ */ import com.nhaarman.expect.expect -import com.nhaarman.mockito_kotlin.any -import com.nhaarman.mockito_kotlin.anyArray -import com.nhaarman.mockito_kotlin.mock -import org.junit.After -import org.junit.Before +import com.nhaarman.mockito_kotlin.createInstance import org.junit.Test -import org.mockito.Mockito -class AnyTest { - - private lateinit var doAnswer: Fake - - @Before - fun setup() { - /* Create an 'any' Mockito state */ - doAnswer = Mockito.doAnswer { }.`when`(mock()) - } - - @After - fun tearDown() { - /* Close `any` Mockito state */ - doAnswer.go(0) - } +class CreateInstanceTest { @Test - fun anyByte() { + fun byte() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toBe(0) } @Test - fun anyShort() { + fun short() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toBe(0) } @Test - fun anyInt() { + fun int() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toBe(0) } @Test - fun anyLong() { + fun long() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toBe(0) } @Test - fun anyDouble() { + fun double() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toBeIn(-0.000001..0.000001) } @Test - fun anyFloat() { + fun float() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toBeIn(-0.000001f..0.000001f) } @Test - fun anyString() { + fun string() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toBeEqualTo("") } @Test - fun anyByteArray() { + fun byteArray() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyShortArray() { + fun shortArray() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyIntArray() { + fun intArray() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyLongArray() { + fun longArray() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyDoubleArray() { + fun doubleArray() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyFloatArray() { + fun floatArray() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test(expected = UnsupportedOperationException::class) - fun anyClassArray_usingAny() { + fun classArray_usingAny() { /* When */ - any>() + createInstance>() } @Test - fun anyClassArray_usingAnyArray() { + fun closedClass() { /* When */ - val result = anyArray>() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyClosedClass() { + fun closedClass_withOpenParameter() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyClosedClass_withOpenParameter() { + fun closedClass_withClosedParameter() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyClosedClass_withClosedParameter() { + fun singleParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anySingleParameterizedClass() { + fun twoParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyTwoParameterizedClass() { + fun threeParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyThreeParameterizedClass() { + fun fourParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyFourParameterizedClass() { + fun fiveParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyFiveParameterizedClass() { + fun sixParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anySixParameterizedClass() { + fun sevenParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anySevenParameterizedClass() { + fun nestedSingleParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyNestedSingleParameterizedClass() { + fun nestedTwoParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyNestedTwoParameterizedClass() { + fun nestedThreeParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyNestedThreeParameterizedClass() { + fun nestedFourParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyNestedFourParameterizedClass() { + fun nestedFiveParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyNestedFiveParameterizedClass() { + fun nestedSixParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyNestedSixParameterizedClass() { + fun nestedSevenParameterizedClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyNestedSevenParameterizedClass() { + fun parameterizedClass() { /* When */ - val result = any() + val result = createInstance>() /* Then */ expect(result).toNotBeNull() } @Test - fun anyParameterizedClass() { + fun nullableParameterClass() { /* When */ - val result = any>() + val result = createInstance() /* Then */ expect(result).toNotBeNull() } @Test - fun anyNullableParameterClass() { + fun stringList() { /* When */ - val result = any() + val result = createInstance>() /* Then */ expect(result).toNotBeNull() } @Test - fun anyStringList() { + fun enum() { /* When */ - val result = any>() + val result = createInstance() /* Then */ - expect(result).toNotBeNull() + expect(result).toBe(MyEnum.VALUE) } @Test - fun anyEnum() { + fun unit() { /* When */ - val result = any() + val result = createInstance() /* Then */ - expect(result).toBe(MyEnum.VALUE) + expect(result).toBe(Unit) } @Test - fun anyUnit() { + fun privateClass() { /* When */ - val result = any() + val result = createInstance() /* Then */ - expect(result).toBe(Unit) + expect(result).toNotBeNull() } + private class PrivateClass private constructor(val data: String) + class ClosedClass class ClosedParameterizedClass(val fake: Fake) class ClosedClosedParameterizedClass(val closed: ClosedParameterizedClass) diff --git a/mockito-kotlin/src/test/kotlin/SpyTest.kt b/mockito-kotlin/src/test/kotlin/SpyTest.kt index e2cc487a..860abf98 100644 --- a/mockito-kotlin/src/test/kotlin/SpyTest.kt +++ b/mockito-kotlin/src/test/kotlin/SpyTest.kt @@ -25,7 +25,9 @@ import com.nhaarman.expect.expect import com.nhaarman.mockito_kotlin.spy +import org.junit.After import org.junit.Test +import org.mockito.Mockito import org.mockito.exceptions.base.MockitoException class SpyTest { @@ -34,6 +36,12 @@ class SpyTest { private val openClassInstance: MyClass = MyClass() private val closedClassInstance: ClosedClass = ClosedClass() + @After + fun a() { + Mockito.validateMockitoUsage() + } + + @Test fun spyInterfaceInstance() { /* When */