File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
core-kotlin-modules/core-kotlin-advanced-3/src/test/kotlin/com/baeldung/guideToAnyUnitAndNothing Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com.baeldung.guideToAnyUnitAndNothing
2
+
3
+ import org.junit.jupiter.api.Assertions.assertNotNull
4
+ import org.junit.jupiter.api.Assertions.assertTrue
5
+ import org.junit.jupiter.api.Test
6
+ import kotlin.test.assertEquals
7
+ import kotlin.test.assertFailsWith
8
+
9
+ class GuideToAnyUnitAndNothingUnitTest {
10
+
11
+ @Test
12
+ fun `prints value for any type` () {
13
+ val intValue = 14
14
+ val stringValue = " Hello Kotlin"
15
+
16
+ assertEquals(" Hello Kotlin" , printAnyType(stringValue))
17
+ assertEquals(14 , printAnyType(intValue))
18
+ }
19
+
20
+ @Test
21
+ fun `shows how to use unit type` () {
22
+ val result = performTask()
23
+ assertNotNull(result)
24
+ }
25
+
26
+ @Test
27
+ fun `shows how to use nothing type` () {
28
+ assertFailsWith<IllegalArgumentException > {
29
+ throwError(" Invalid argument" )
30
+ }
31
+ }
32
+ }
33
+ fun printAnyType (value : Any ): Any {
34
+ return value
35
+ }
36
+ fun performTask (): Unit {
37
+ println ()
38
+ }
39
+ fun throwError (message : String ): Nothing {
40
+ throw IllegalArgumentException (message)
41
+ }
You can’t perform that action at this time.
0 commit comments