commonMain.com.copperleaf.ballast.test.internal.vm.TestInterceptor.kt Maven / Gradle / Ivy
package com.copperleaf.ballast.test.internal.vm
import com.copperleaf.ballast.BallastInterceptor
import com.copperleaf.ballast.test.TestResults
internal class TestInterceptor :
BallastInterceptor, Events, State> {
// Inputs
// ---------------------------------------------------------------------------------------------------------------------
private val acceptedInputs = mutableListOf()
override suspend fun onInputAccepted(input: TestViewModel.Inputs) {
when (input) {
is TestViewModel.Inputs.AwaitInput -> {
acceptedInputs += input.normalInput
}
is TestViewModel.Inputs.ProcessInput -> {
acceptedInputs += input.normalInput
}
is TestViewModel.Inputs.TestCompleted -> {
}
}
}
private val rejectedInputs = mutableListOf()
override suspend fun onInputRejected(input: TestViewModel.Inputs) {
when (input) {
is TestViewModel.Inputs.AwaitInput -> {
rejectedInputs += input.normalInput
}
is TestViewModel.Inputs.ProcessInput -> {
rejectedInputs += input.normalInput
}
is TestViewModel.Inputs.TestCompleted -> {
}
}
}
private val droppedInputs = mutableListOf()
override fun onInputDropped(input: TestViewModel.Inputs) {
when (input) {
is TestViewModel.Inputs.AwaitInput -> {
droppedInputs += input.normalInput
}
is TestViewModel.Inputs.ProcessInput -> {
droppedInputs += input.normalInput
}
is TestViewModel.Inputs.TestCompleted -> {
}
}
}
private val successfulInputs = mutableListOf()
override suspend fun onInputHandledSuccessfully(input: TestViewModel.Inputs) {
when (input) {
is TestViewModel.Inputs.AwaitInput -> {
successfulInputs += input.normalInput
}
is TestViewModel.Inputs.ProcessInput -> {
successfulInputs += input.normalInput
}
is TestViewModel.Inputs.TestCompleted -> {
}
}
}
private val cancelledInputs = mutableListOf()
override suspend fun onInputCancelled(input: TestViewModel.Inputs) {
when (input) {
is TestViewModel.Inputs.AwaitInput -> {
cancelledInputs += input.normalInput
}
is TestViewModel.Inputs.ProcessInput -> {
cancelledInputs += input.normalInput
}
is TestViewModel.Inputs.TestCompleted -> {
}
}
}
private val inputHandlerErrors = mutableListOf>()
override suspend fun onInputHandlerError(input: TestViewModel.Inputs, exception: Throwable) {
when (input) {
is TestViewModel.Inputs.AwaitInput -> {
inputHandlerErrors += input.normalInput to exception
}
is TestViewModel.Inputs.ProcessInput -> {
inputHandlerErrors += input.normalInput to exception
}
is TestViewModel.Inputs.TestCompleted -> {
}
}
}
// Events
// ---------------------------------------------------------------------------------------------------------------------
private val events = mutableListOf()
override suspend fun onEventEmitted(event: Events) {
events += event
}
private val eventHandlerErrors = mutableListOf>()
override suspend fun onEventHandlerError(event: Events, exception: Throwable) {
eventHandlerErrors += event to exception
}
// States
// ---------------------------------------------------------------------------------------------------------------------
private val states = mutableListOf()
override suspend fun onStateEmitted(state: State) {
states += state
}
// Other
// ---------------------------------------------------------------------------------------------------------------------
private val unhandledErrors = mutableListOf()
override fun onUnhandledError(exception: Throwable) {
unhandledErrors += exception
}
internal fun getResults(): TestResults {
return TestResults(
acceptedInputs = acceptedInputs.toList(),
rejectedInputs = rejectedInputs.toList(),
droppedInputs = droppedInputs.toList(),
successfulInputs = successfulInputs.toList(),
cancelledInputs = cancelledInputs.toList(),
inputHandlerErrors = inputHandlerErrors.toList(),
events = events.toList(),
eventHandlerErrors = eventHandlerErrors.toList(),
states = states.toList(),
unhandledErrors = unhandledErrors.toList(),
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy