BAEL-2230 Equivalent of Java static final in Kotlin (#5848)
* constant unit test * kotlin const
This commit is contained in:
parent
2bec14597a
commit
4a55426727
|
@ -0,0 +1,17 @@
|
|||
import com.baeldung.kotlin.constant.TestKotlinConstantClass
|
||||
import com.baeldung.kotlin.constant.TestKotlinConstantObject
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ConstantUnitTest {
|
||||
|
||||
@Test
|
||||
fun givenConstant_whenCompareWithActualValue_thenReturnTrue() {
|
||||
assertEquals(10, TestKotlinConstantObject.COMPILE_TIME_CONST)
|
||||
assertEquals(30, TestKotlinConstantObject.RUN_TIME_CONST)
|
||||
assertEquals(20, TestKotlinConstantObject.JAVA_STATIC_FINAL_FIELD)
|
||||
|
||||
assertEquals(40, TestKotlinConstantClass.COMPANION_OBJECT_NUMBER)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.kotlin.constant
|
||||
|
||||
|
||||
class TestKotlinConstantClass {
|
||||
companion object {
|
||||
const val COMPANION_OBJECT_NUMBER = 40
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.kotlin.constant
|
||||
|
||||
|
||||
object TestKotlinConstantObject {
|
||||
const val COMPILE_TIME_CONST = 10
|
||||
|
||||
val RUN_TIME_CONST: Int
|
||||
|
||||
@JvmField
|
||||
val JAVA_STATIC_FINAL_FIELD = 20
|
||||
|
||||
init {
|
||||
RUN_TIME_CONST = TestKotlinConstantObject.COMPILE_TIME_CONST + 20;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue