1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
-
17
16
package org.springframework.core
18
17
19
- import java.lang.reflect.Method
20
-
21
- import org.junit.Before
22
18
import org.junit.Test
23
-
24
19
import org.junit.Assert.*
20
+ import java.lang.reflect.Method
25
21
26
22
/* *
27
23
* Tests for Kotlin support in [MethodParameter].
@@ -32,36 +28,58 @@ import org.junit.Assert.*
32
28
*/
33
29
class KotlinMethodParameterTests {
34
30
35
- lateinit var nullableMethod: Method
31
+ private val nullableMethod: Method = javaClass.getMethod( " nullable " , String :: class .java)
36
32
37
- lateinit var nonNullableMethod: Method
33
+ private val nonNullableMethod = javaClass.getMethod( " nonNullable " , String :: class .java)
38
34
35
+ private val innerClassConstructor = InnerClass ::class .java.getConstructor(KotlinMethodParameterTests ::class .java)
39
36
40
- @Before
41
- @Throws(NoSuchMethodException ::class )
42
- fun setup () {
43
- nullableMethod = javaClass.getMethod(" nullable" , String ::class .java)
44
- nonNullableMethod = javaClass.getMethod(" nonNullable" , String ::class .java)
45
- }
37
+ private val innerClassWithParametersConstructor = InnerClassWithParameter ::class .java
38
+ .getConstructor(KotlinMethodParameterTests ::class .java, String ::class .java, String ::class .java)
39
+
40
+ private val regularClassConstructor = RegularClass ::class .java.getConstructor(String ::class .java, String ::class .java)
46
41
47
42
48
43
@Test
49
44
fun `Method parameter nullability` () {
50
- assertTrue(MethodParameter (nullableMethod, 0 ).isOptional() )
51
- assertFalse(MethodParameter (nonNullableMethod, 0 ).isOptional() )
45
+ assertTrue(MethodParameter (nullableMethod, 0 ).isOptional)
46
+ assertFalse(MethodParameter (nonNullableMethod, 0 ).isOptional)
52
47
}
53
48
54
49
@Test
55
50
fun `Method return type nullability` () {
56
- assertTrue(MethodParameter (nullableMethod, - 1 ).isOptional())
57
- assertFalse(MethodParameter (nonNullableMethod, - 1 ).isOptional())
51
+ assertTrue(MethodParameter (nullableMethod, - 1 ).isOptional)
52
+ assertFalse(MethodParameter (nonNullableMethod, - 1 ).isOptional)
53
+ }
54
+
55
+ @Test // SPR-17222
56
+ fun `Inner class constructor` () {
57
+ assertFalse(MethodParameter (innerClassConstructor, 0 ).isOptional)
58
+
59
+ assertFalse(MethodParameter (innerClassWithParametersConstructor, 0 ).isOptional)
60
+ assertFalse(MethodParameter (innerClassWithParametersConstructor, 1 ).isOptional)
61
+ assertTrue(MethodParameter (innerClassWithParametersConstructor, 2 ).isOptional)
62
+ }
63
+
64
+ @Test
65
+ fun `Regular class constructor` () {
66
+ assertFalse(MethodParameter (regularClassConstructor, 0 ).isOptional)
67
+ assertTrue(MethodParameter (regularClassConstructor, 1 ).isOptional)
58
68
}
59
69
60
70
61
- @Suppress(" unused" , " unused_parameter" )
62
- fun nullable (p1 : String? ): Int? = 42
71
+ @Suppress(" unused_parameter" )
72
+ fun nullable (nullable : String? ): Int? = 42
73
+
74
+ @Suppress(" unused_parameter" )
75
+ fun nonNullable (nonNullable : String ): Int = 42
76
+
77
+ inner class InnerClass
78
+
79
+ @Suppress(" unused_parameter" )
80
+ inner class InnerClassWithParameter (nonNullable : String , nullable : String? )
63
81
64
- @Suppress(" unused " , " unused_parameter" )
65
- fun nonNullable ( p1 : String ): Int = 42
82
+ @Suppress(" unused_parameter" )
83
+ class RegularClass ( nonNullable : String , nullable : String? )
66
84
67
85
}
0 commit comments