com.tinder.scarlet.testutils.TestUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of test-utils Show documentation
Show all versions of test-utils Show documentation
A Retrofit inspired WebSocket client for Kotlin, Java, and Android.
/*
* © 2018 Match Group, LLC.
*/
@file:JvmName("TestUtils")
package com.tinder.scarlet.testutils
import com.tinder.scarlet.Event
import com.tinder.scarlet.Lifecycle
import com.tinder.scarlet.Message
import com.tinder.scarlet.ShutdownReason
import com.tinder.scarlet.State
import com.tinder.scarlet.Stream
import com.tinder.scarlet.WebSocket
import org.assertj.core.api.Assertions.assertThat
fun Stream.test() = TestStreamObserver(this)
inline fun any(noinline assertion: T.() -> Unit = {}): ValueAssert = ValueAssert()
.assert { assertThat(this).isInstanceOf(T::class.java) }
.assert(assertion)
inline fun ValueAssert>.withLifecycleState() =
assert {
assertThat(state).isInstanceOf(T::class.java)
}
inline fun ValueAssert>.withWebSocketEvent() = assert {
assertThat(event).isInstanceOf(T::class.java)
}
inline fun ValueAssert>.withState() = assert {
assertThat(state).isInstanceOf(T::class.java)
}
fun ValueAssert.containingText(expectedText: String) = assert {
assertThat(message).isInstanceOf(Message.Text::class.java)
val (text) = message as Message.Text
assertThat(text).isEqualTo(expectedText)
}
fun ValueAssert.containingBytes(expectedBytes: ByteArray) = assert {
assertThat(message).isInstanceOf(Message.Bytes::class.java)
val (bytes) = message as Message.Bytes
assertThat(bytes).isEqualTo(expectedBytes)
}
fun ValueAssert.withClosingReason(
expectedShutdownReason: ShutdownReason
) = assert {
assertThat(shutdownReason).isEqualTo(expectedShutdownReason)
}
fun ValueAssert.withClosedReason(expectedShutdownReason: ShutdownReason) = assert {
assertThat(shutdownReason).isEqualTo(expectedShutdownReason)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy