Hello everybody, I have a model like ```sealed int...
# test
d
Hello everybody, I have a model like
Copy code
sealed interface AffectsA
sealed interface AffectsB

sealed interface Action {

  object Act1 : Action, AffectsA
  object Act2 : Action, AffectsA, AffectsB
  object Act3 : Action, AffectsB
}
and a class like
Copy code
class Reducer(
  private val subReducer1: X,
  private val subReducer2: Y
) {

  fun reduce(state: State, action: Action): State =
    when (action) {
      is Act1 -> state.copy(
        a = subReducer1.reduce(state.a, action)
      )
      Act2 -> state.copy(
        a = subReducer1.reduce(state.a, action),
        b = subReducer2.reduce(state.b, action)
      )
      Act3 -> state.copy(
        b = subReducer2.reduce(state.b, action)
      )
    }
}
I wanna test that for every action, the correct sub-reducer is called. Something like
Copy code
reducer.reduce(someState, Act2)
verify {
  subReducer1.reduce(someState.a, Act2)
  subReducer2.reduce(someState.b, Act2)
}

/// 

reducer.reduce(someState, Act3)
verify {
  subReducer1 wasNot Called
  subReducer2.reduce(someState.b, Act2)
}
I usually like to use
org.junit.runners.Parameterized
for these cases, but I wanna ensure that all the cases are covered, a.k.a. every sub-type of Action. Got any idea?
d
Or maybe using reflection to get all the sealed class instances? And then https://kotest.io/docs/framework/datatesting/data-driven-testing.html
d
No, I never tried! I’ll check what it offers! Thanks!