TestMosaicBuilder

class TestMosaicBuilder(testContext: TestScope)(source)

A builder for creating TestMosaic instances with mocked Tile implementations.

This class provides a fluent API for setting up test scenarios by configuring mock tiles with various behaviors. It supports both Tile and MultiTile mocks with different behaviors like success, failure, delays, and custom logic. Inside runTest, use mosaicBuilder to share its TestScope and scheduler.

Basic Usage

val testMosaic = mosaicBuilder()
.withMockTile(MyTile, "test data")
.withFailedTile(OtherTile, RuntimeException("Test error"))
.withDelayedTile(SlowTile, "delayed data", 1000) // 1 second delay
.build()

MultiTile Usage

val testMosaic = mosaicBuilder()
.withMockTile(UserTile, mapOf("user1" to user1, "user2" to user2))
.withCustomTile(ProfileTile) { keys ->
// Custom logic based on requested keys
keys.associateWith { key -> createMockProfile(key) }
}
.build()

Constructors

Link copied to clipboard
constructor(testContext: TestScope)

Functions

Link copied to clipboard

Builds and returns a configured TestMosaic instance.

Link copied to clipboard
inline fun <T : Any> withCanvasSource(obj: T): TestMosaicBuilder

Adds a source to the canvas with the specified object.

inline fun <T : Any> withCanvasSource(qualifier: String, obj: T): TestMosaicBuilder

Adds a source to the canvas with the specified object and qualifier.

fun <T : Any, V : T> withCanvasSource(clazz: KClass<T>, obj: V): TestMosaicBuilder

Adds a source to the canvas with the specified class and object. Allows for passing in a superclass as the retrieval type.

Adds a source to the canvas using a CanvasKey.

fun <T : Any, V : T> withCanvasSource(clazz: KClass<T>, qualifier: String, obj: V): TestMosaicBuilder

Adds a source to the canvas with the specified class, qualifier, and object.

Link copied to clipboard
@JvmName(name = "withCustomMultiTile")
fun <K : Any, V> withCustomTile(tile: MultiTile<K, V>, provider: suspend Mosaic.(Set<K>) -> Map<K, V>): TestMosaicBuilder

Adds a mock MultiTile with custom behavior.

fun <V> withCustomTile(tile: Tile<V>, provider: suspend Mosaic.() -> V): TestMosaicBuilder

Adds a mock Tile with custom behavior.

Link copied to clipboard
@JvmName(name = "withDelayedMultiTile")
fun <K : Any, V> withDelayedTile(tile: MultiTile<K, V>, response: Map<K, V>, delayMs: Long): TestMosaicBuilder

Adds a mock MultiTile that delays before returning responses.

fun <V> withDelayedTile(tile: Tile<V>, response: V, delayMs: Long): TestMosaicBuilder

Adds a mock Tile that delays before returning the response.

Link copied to clipboard
@JvmName(name = "withFailedMultiTile")
fun withFailedTile(tile: MultiTile<*, *>, throwable: Throwable): TestMosaicBuilder

Adds a mock MultiTile that fails with the specified exception.

fun withFailedTile(tile: Tile<*>, throwable: Throwable): TestMosaicBuilder

Adds a mock Tile that fails with the specified exception.

Link copied to clipboard
@JvmName(name = "withMockMultiTile")
fun <K : Any, V> withMockTile(tile: MultiTile<K, V>, response: Map<K, V>): TestMosaicBuilder

Adds a mock MultiTile that returns the specified responses for given keys.

fun <V> withMockTile(tile: Tile<V>, response: V): TestMosaicBuilder

Adds a mock Tile that returns the specified response.