File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
core-kotlin-modules/core-kotlin-7/src/test/kotlin/com/baeldung/kproperty Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com.baeldung.kproperty
2
+
3
+ import org.junit.jupiter.api.Assertions
4
+ import org.junit.jupiter.api.Test
5
+
6
+ class KPropertyTest {
7
+
8
+ @Test
9
+ fun `can get property name of a class's property statically` () {
10
+ class MyClass (val age : Int , var name : String , val next : MyClass ? )
11
+
12
+ Assertions .assertEquals(" next" , MyClass ::next.name)
13
+ }
14
+
15
+ @Test
16
+ fun `can get property name of an instance's property` () {
17
+ class MyClass (val age : Int , var name : String , val next : MyClass ? )
18
+ val instance = MyClass (5 , " test" , null )
19
+
20
+ Assertions .assertEquals(" next" , instance::next.name)
21
+ }
22
+
23
+ @Test
24
+ fun `can get the name of a function` () {
25
+ fun isValid (num : Int , name : String ): Boolean = num > 0 && name.isNotBlank()
26
+
27
+ Assertions .assertEquals(" isValid" , ::isValid.name)
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments