[BAEL-19886] - moved related articles to the new core-kotlin-modules/core-kotlin module

This commit is contained in:
catalin-burcea
2020-01-03 18:33:14 +02:00
parent 202c7d639a
commit f145e70c5b
42 changed files with 106 additions and 76 deletions

View File

@@ -1,14 +0,0 @@
package com.baeldung.kotlin
import java.util.concurrent.ThreadLocalRandom
class ListExtension {
fun <T> List<T>.random(): T? {
if (this.isEmpty()) return null
return get(ThreadLocalRandom.current().nextInt(count()))
}
fun <T> getRandomElementOfList(list: List<T>): T? {
return list.random()
}
}

View File

@@ -1,19 +0,0 @@
package com.baeldung.kotlin
import com.baeldung.kotlin.ListExtension
import org.junit.Test
import kotlin.test.assertTrue
class ListExtensionTest {
@Test
fun givenList_whenExecuteExtensionFunctionOnList_shouldReturnRandomElementOfList(){
//given
val elements = listOf("a", "b", "c")
//when
val result = ListExtension().getRandomElementOfList(elements)
//then
assertTrue(elements.contains(result))
}
}