commonTest.channels.ChannelFactoryTest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-coroutines-core
Show all versions of kotlinx-coroutines-core
Coroutines support libraries for Kotlin
/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines.channels
import kotlinx.coroutines.*
import kotlin.test.*
class ChannelFactoryTest : TestBase() {
@Test
fun testRendezvousChannel() {
assertTrue(Channel() is RendezvousChannel)
assertTrue(Channel(0) is RendezvousChannel)
}
@Test
fun testLinkedListChannel() {
assertTrue(Channel(Channel.UNLIMITED) is LinkedListChannel)
assertTrue(Channel(Channel.UNLIMITED, BufferOverflow.DROP_OLDEST) is LinkedListChannel)
assertTrue(Channel(Channel.UNLIMITED, BufferOverflow.DROP_LATEST) is LinkedListChannel)
}
@Test
fun testConflatedChannel() {
assertTrue(Channel(Channel.CONFLATED) is ConflatedChannel)
assertTrue(Channel(1, BufferOverflow.DROP_OLDEST) is ConflatedChannel)
}
@Test
fun testArrayChannel() {
assertTrue(Channel(1) is ArrayChannel)
assertTrue(Channel(1, BufferOverflow.DROP_LATEST) is ArrayChannel)
assertTrue(Channel(10) is ArrayChannel)
}
@Test
fun testInvalidCapacityNotSupported() {
assertFailsWith { Channel(-3) }
}
@Test
fun testUnsupportedBufferOverflow() {
assertFailsWith { Channel(Channel.CONFLATED, BufferOverflow.DROP_OLDEST) }
assertFailsWith { Channel(Channel.CONFLATED, BufferOverflow.DROP_LATEST) }
}
}