diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/ListUtil.kt b/core-kotlin/src/main/kotlin/com/baeldung/kotlin/ListUtil.kt deleted file mode 100644 index 0a48a42e13..0000000000 --- a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/ListUtil.kt +++ /dev/null @@ -1,9 +0,0 @@ -@file:JvmName("Lists") -package com.baeldung.kotlin - -fun MutableList.swap(firstIndex: Int, secondIndex: Int): MutableList { - val tmp = this[firstIndex] - this[firstIndex] = this[secondIndex] - this[secondIndex] = tmp - return this -} diff --git a/core-kotlin/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt b/core-kotlin/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt new file mode 100644 index 0000000000..ca57b2965e --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt @@ -0,0 +1,9 @@ +@file:JvmName("Strings") +package com.baeldung.kotlin + +fun String.escapeForXml() : String { + return this + .replace("&", "&") + .replace("<", "<") + .replace(">", ">") +} diff --git a/core-kotlin/src/test/java/com/baeldung/kotlin/ListUtilTest.java b/core-kotlin/src/test/java/com/baeldung/kotlin/ListUtilTest.java deleted file mode 100644 index 4184cc0878..0000000000 --- a/core-kotlin/src/test/java/com/baeldung/kotlin/ListUtilTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.kotlin; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; - -import static com.baeldung.kotlin.Lists.*; - -public class ListUtilTest { - - @Test - public void shouldSwapTwoElementsInList() { - List list = Arrays.asList(0, 1, 2); - - List swappedElements = swap(list, 1, 2); - - Assert.assertEquals(swappedElements, Arrays.asList(0, 2, 1)); - } - -} diff --git a/core-kotlin/src/test/java/com/baeldung/kotlin/StringUtilTest.java b/core-kotlin/src/test/java/com/baeldung/kotlin/StringUtilTest.java new file mode 100644 index 0000000000..e02d3c4341 --- /dev/null +++ b/core-kotlin/src/test/java/com/baeldung/kotlin/StringUtilTest.java @@ -0,0 +1,30 @@ +package com.baeldung.kotlin; + +import kotlin.text.StringsKt; +import org.junit.Assert; +import org.junit.Test; + +import static com.baeldung.kotlin.Strings.*; + + +public class StringUtilTest { + + @Test + public void shouldSwapTwoElementsInList() { + String xml = "hi"; + + String escapedXml = escapeForXml(xml); + + Assert.assertEquals("<a>hi</a>", escapedXml); + } + + @Test + public void callingBuiltInKotlinExtensionMethod() { + String name = "john"; + + String capitalizedName = StringsKt.capitalize(name); + + Assert.assertEquals("John", capitalizedName); + } + +} diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt index 09ce898860..44c5cd0ece 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt @@ -6,13 +6,6 @@ import org.junit.Test class ExtensionMethods { @Test fun simpleExtensionMethod() { - fun String.escapeForXml() : String { - return this - .replace("&", "&") - .replace("<", "<") - .replace(">", ">") - } - Assert.assertEquals("Nothing", "Nothing".escapeForXml()) Assert.assertEquals("<Tag>", "".escapeForXml()) Assert.assertEquals("a&b", "a&b".escapeForXml())