Skip to content

Commit 2bfa130

Browse files
committed
unit tests added
1 parent 56b5933 commit 2bfa130

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)