File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
main/kotlin/com/nhaarman/mockito_kotlin Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ import kotlin.reflect.defaultType
41
41
import kotlin.reflect.jvm.isAccessible
42
42
import kotlin.reflect.jvm.javaType
43
43
import kotlin.reflect.jvm.jvmName
44
+ import java.lang.reflect.Array as JavaArray
44
45
45
46
/* *
46
47
* A collection of functions that tries to create an instance of
@@ -51,6 +52,7 @@ import kotlin.reflect.jvm.jvmName
51
52
* Checks whether the resource file to enable mocking of final classes is present.
52
53
*/
53
54
private var mockMakerInlineEnabled: Boolean? = null
55
+
54
56
private fun mockMakerInlineEnabled (jClass : Class <out Any >): Boolean {
55
57
return mockMakerInlineEnabled ? :
56
58
jClass.getResource(" mockito-extensions/org.mockito.plugins.MockMaker" )?.let {
@@ -137,7 +139,10 @@ private fun <T : Any> KClass<T>.toArrayInstance(): T {
137
139
" LongArray" -> longArrayOf()
138
140
" DoubleArray" -> doubleArrayOf()
139
141
" FloatArray" -> floatArrayOf()
140
- else -> throw UnsupportedOperationException (" Cannot create a generic array for $simpleName . Use createArrayInstance() or anyArray() instead." )
142
+ else -> {
143
+ val name = java.name.drop(2 ).dropLast(1 )
144
+ return JavaArray .newInstance(Class .forName(name), 0 ) as T
145
+ }
141
146
} as T
142
147
}
143
148
Original file line number Diff line number Diff line change @@ -159,10 +159,13 @@ class CreateInstanceTest {
159
159
expect(result).toNotBeNull()
160
160
}
161
161
162
- @Test(expected = UnsupportedOperationException :: class )
162
+ @Test
163
163
fun classArray_usingAny () {
164
164
/* When */
165
- createInstance<Array <Open >>()
165
+ val result = createInstance<Array <Open >>()
166
+
167
+ /* Then */
168
+ expect(result).toBeInstanceOf<Array <Open >>()
166
169
}
167
170
168
171
@Test
You can’t perform that action at this time.
0 commit comments