kotest-assertions-core / io.kotest.matchers.collections / kotlin.collections.Collection / shouldBeSingleton

shouldBeSingleton

fun <T> Collection<T>.shouldBeSingleton(): Unit

Verifies this collection contains only one element

This assertion is an alias to collection shouldHaveSize 1. This will pass if the collection have exactly one element (definition of a Singleton Collection)

listOf(1).shouldBeSingleton()    // Assertion passes
listOf(1, 2).shouldBeSingleton() // Assertion fails

See Also

shouldHaveSize

shouldNotBeSingleton

shouldHaveSingleElement

inline fun <T> Collection<T>.shouldBeSingleton(fn: (T) -> Unit): Unit