File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
core-kotlin-modules/core-kotlin-lang-oop-4/src/test/kotlin/unitAndVoidMismatch Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ package unitAndVoidMismatch
2
+
3
+ import org.junit.jupiter.api.Test
4
+ import org.slf4j.LoggerFactory
5
+
6
+ fun customGreetingVoid (name : String , greeting : (String ) -> Void ) = greeting(name)
7
+
8
+ fun customGreetingUnit (name : String , greeting : (String ) -> Unit ) = greeting(name)
9
+
10
+ class UnitAndVoidTypeMismatchUnitTest {
11
+ val log = LoggerFactory .getLogger(this ::class .java)
12
+
13
+ @Test
14
+ fun `when calling customGreetingVoid method, then code does not compile` () {
15
+ /* the below code doesn't compile
16
+ ---------------------------------
17
+ customGreetingVoid("Tom Hanks"){
18
+ log.info("Hi $it, how do you do?")
19
+ }
20
+
21
+ customGreetingVoid("Kai"){
22
+ log.info("Hello $it")
23
+ null
24
+ }
25
+ */
26
+ }
27
+
28
+ @Test
29
+ fun `when calling customGreetingUnit method, then works as expected` () {
30
+ customGreetingUnit(" Tom Cruise" ) {
31
+ log.info(" Hi $it , how are you doing?" )
32
+ }
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments