winter-junit4 / io.jentz.winter.junit4 / GraphLifecycleTestRule

GraphLifecycleTestRule

abstract class GraphLifecycleTestRule : SimplePlugin, TestRule

JUnit4 test rule that allows to hook into the io.jentz.winter.Graph lifecycle.

This registers itself as Winter plugin on application before executing a test and unregisters itself afterwards.

Sample where we replace a view model in a presentation graph with a test view model:

val testViewModel = TestViewModel<ViewState>()

@get:Rule
val winterTestRule = object : GraphLifecycleTestRule() {
  override fun initializingGraph(parentGraph: Graph?, builder: ComponentBuilder) {
    if (builder.qualifier == "presentation") {
      builder.apply {
        singleton<ViewModel<QuotesViewState>>(generics = true, override = true) {
          viewModel
        }
      }
    }
  }
}

Constructors

<init>

GraphLifecycleTestRule(application: WinterApplication = Winter)

JUnit4 test rule that allows to hook into the io.jentz.winter.Graph lifecycle.

Functions

apply

fun apply(base: Statement, description: Description): Statement

Inheritors

ExtendGraphTestRule

class ExtendGraphTestRule : GraphLifecycleTestRule

Test rule that takes a component qualifier and a ComponentBuilderBlock and extends the Graph with componentQualifier by applying the ComponentBuilderBlock.