BAEL
This commit is contained in:
parent
b84b7117a6
commit
6fe5f008a7
|
@ -1,9 +0,0 @@
|
|||
@file:JvmName("Lists")
|
||||
package com.baeldung.kotlin
|
||||
|
||||
fun <T> MutableList<T>.swap(firstIndex: Int, secondIndex: Int): MutableList<T> {
|
||||
val tmp = this[firstIndex]
|
||||
this[firstIndex] = this[secondIndex]
|
||||
this[secondIndex] = tmp
|
||||
return this
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
@file:JvmName("Strings")
|
||||
package com.baeldung.kotlin
|
||||
|
||||
fun String.escapeForXml() : String {
|
||||
return this
|
||||
.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
}
|
|
@ -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<Integer> list = Arrays.asList(0, 1, 2);
|
||||
|
||||
List<Integer> swappedElements = swap(list, 1, 2);
|
||||
|
||||
Assert.assertEquals(swappedElements, Arrays.asList(0, 2, 1));
|
||||
}
|
||||
|
||||
}
|
|
@ -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 = "<a>hi</a>";
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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>", "<Tag>".escapeForXml())
|
||||
Assert.assertEquals("a&b", "a&b".escapeForXml())
|
||||
|
|
Loading…
Reference in New Issue