Skip to content

Commit 4edcd08

Browse files
Walter Gómezmaibin
authored andcommitted
Kotlin jvm field (eugenp#2610)
* Add project for hibernate immutable article Add Event entity Add hibernate configuration file Add hibernateutil for configuration Add test to match snippets from article * Update master * Jvm Field Add sample classes Include test for sample classes
1 parent 22015c8 commit 4edcd08

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.kotlin
2+
3+
class JvmSample(text:String) {
4+
@JvmField
5+
val sampleText:String = text
6+
}
7+
8+
class CompanionSample {
9+
companion object {
10+
@JvmField val MAX_LIMIT = 20
11+
}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.kotlin
2+
3+
import org.junit.Before
4+
import org.junit.Test
5+
import kotlin.test.assertTrue
6+
7+
class JvmSampleTest {
8+
9+
var sample = ""
10+
11+
@Before
12+
fun setUp() {
13+
sample = JvmSample("Hello!").sampleText
14+
}
15+
16+
@Test
17+
fun givenField_whenCheckValue_thenMatchesValue() {
18+
assertTrue(sample == "Hello!")
19+
}
20+
21+
@Test
22+
fun givenStaticVariable_whenCheckValue_thenMatchesValue() {
23+
// Sample when is treated as a static variable
24+
assertTrue(CompanionSample.MAX_LIMIT == 20)
25+
}
26+
}

0 commit comments

Comments
 (0)