withComputation

fun <C : Contract.Computation<D?>, D : Any> withComputation(contract: C, data: () -> D?): TransmissionTest

Adds a mock computation that provides computed results for the specified contract during testing.

This method creates a mock transformer that provides computation results when other transformers request computation through the specified contract. The result is provided by the lambda function which is called each time the computation is requested.

Return

This TransmissionTest instance for method chaining

Example usage:

transformer.test()
.withComputation(AnalyticsService.userStatsContract) {
UserStats(loginCount = 5, lastLogin = Date())
}
.testSignal(ProfileSignal.LoadStats) { /* assertions */}

Parameters

C

The computation contract type

D

The type of data returned by the computation

contract

The computation contract to mock

data

Lambda function that provides the computation result


fun <C : Contract.ComputationWithArgs<A, D?>, D : Any, A : Any> withComputation(contract: C, data: () -> D?): TransmissionTest

Adds a mock computation with arguments that provides computed results for the specified contract during testing.

This method creates a mock transformer that provides computation results when other transformers request computation with arguments through the specified contract. The result is provided by the lambda function which is called each time the computation is requested with arguments.

Note: Currently the arguments are not passed to the data lambda function due to the mock implementation. This will be improved in future versions.

Return

This TransmissionTest instance for method chaining

Example usage:

transformer.test()
.withComputation(SearchService.searchUsersContract) {
listOf(User("john", "john@example.com"))
}
.testSignal(SearchSignal.SearchUsers("john")) { /* assertions */}

Parameters

C

The computation contract type

D

The type of data returned by the computation

A

The type of arguments passed to the computation

contract

The computation contract to mock

data

Lambda function that provides the computation result