Bael 2145 concatenate strings in kotlin (#5208)

* BAEL-2145

* BAEL-2145

* BAEL-2145
This commit is contained in:
Krzysztof Majewski 2018-09-15 13:57:25 +00:00 committed by Grzegorz Piwowarek
parent 05e1700fb7
commit 2e0edf12b1
1 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,48 @@
package com.baeldung.kotlin
import org.junit.Test
import kotlin.test.assertEquals
class StringConcatenationTest {
@Test
fun givenTwoStrings_concatenateWithTemplates_thenEquals() {
val a = "Hello"
val b = "Baeldung"
val c = "$a $b"
assertEquals("Hello Baeldung", c)
}
@Test
fun givenTwoStrings_concatenateWithPlusOperator_thenEquals() {
val a = "Hello"
val b = "Baeldung"
val c = a + " " + b
assertEquals("Hello Baeldung", c)
}
@Test
fun givenTwoStrings_concatenateWithStringBuilder_thenEquals() {
val a = "Hello"
val b = "Baeldung"
val builder = StringBuilder()
builder.append(a).append(" ").append(b)
val c = builder.toString()
assertEquals("Hello Baeldung", c)
}
@Test
fun givenTwoStrings_concatenateWithPlusMethod_thenEquals() {
val a = "Hello"
val b = "Baeldung"
val c = a.plus(" ").plus(b)
assertEquals("Hello Baeldung", c)
}
}