mirror of
https://github.com/bitwarden/android.git
synced 2026-03-24 23:32:29 -05:00
[PM-22786] Migrate PersistentListExtensions to core module (#5380)
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package com.bitwarden.core.util
|
||||
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
/**
|
||||
* Creates an immutable [ImmutableList] of the given [elements] excluding the null ones.
|
||||
*/
|
||||
fun <T : Any> persistentListOfNotNull(vararg elements: T?): ImmutableList<T> =
|
||||
elements.filterNotNull().toImmutableList()
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.bitwarden.core.util
|
||||
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class PersistentListExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `PersistentListOfNotNull should filter out null values`() {
|
||||
val expected = persistentListOf("Hello", "World")
|
||||
|
||||
val result = persistentListOfNotNull(
|
||||
"Hello",
|
||||
null,
|
||||
"World",
|
||||
null,
|
||||
null,
|
||||
)
|
||||
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user