BAEL-2376 Inline classes in kotlin (#5842)

* BAEL-2376 Inline classes in kotlin

* BAEL-2376 Move classes
This commit is contained in:
Laurentiu Delcea 2018-12-16 18:22:22 +02:00 committed by Diego Moreira
parent de3479ca78
commit d8e34dc9f2
4 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package com.baeldung.inline.classes
interface Drawable {
fun draw()
}
inline class CircleRadius(private val circleRadius : Double) : Drawable {
val diameterOfCircle get() = 2 * circleRadius
fun areaOfCircle() = 3.14 * circleRadius * circleRadius
override fun draw() {
println("Draw my circle")
}
}

View File

@ -0,0 +1,3 @@
package com.baeldung.inline.classes
inline class InlineDoubleWrapper(val doubleValue : Double)

View File

@ -0,0 +1,19 @@
package com.baeldung.inline.classes
import org.junit.Test
import kotlin.test.assertEquals
class CircleRadiusTest {
@Test
fun givenRadius_ThenDiameterIsCorrectlyCalculated() {
val radius = CircleRadius(5.0)
assertEquals(10.0, radius.diameterOfCircle)
}
@Test
fun givenRadius_ThenAreaIsCorrectlyCalculated() {
val radius = CircleRadius(5.0)
assertEquals(78.5, radius.areaOfCircle())
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.inline.classes
import org.junit.Test
import kotlin.test.assertEquals
class InlineDoubleWrapperTest {
@Test
fun whenInclineClassIsUsed_ThenPropertyIsReadCorrectly() {
val piDoubleValue = InlineDoubleWrapper(3.14)
assertEquals(3.14, piDoubleValue.doubleValue)
}
}