Skip to content

Commit

Permalink
Fix mocking of action formula. (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laimiux committed Jan 4, 2024
1 parent e8c23c0 commit 33f9709
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ class MockitoFormulaTest {
assertThat(formula.type()).isEqualTo(MyFormula::class)
}

@Test fun mockActionFormula() {
val testFormula = ReplacementFormula().implementation()
val formula = mock<MyActionFormula>(defaultAnswer = CallsRealMethods())
whenever(formula.implementation()).thenReturn(testFormula)
assertThat(formula.implementation()).isEqualTo(testFormula)
assertThat(formula.type()).isEqualTo(MyActionFormula::class)
}

class MyFormula : StatelessFormula<Unit, Unit>() {
override fun Snapshot<Unit, Unit>.evaluate(): Evaluation<Unit> {
return Evaluation(Unit)
}
}

class MyActionFormula : ActionFormula<Unit, Unit>() {
override fun initialValue(input: Unit) = Unit

override fun action(input: Unit): Action<Unit> {
return Action.onData(Unit)
}
}

class ReplacementFormula : StatelessFormula<Unit, Unit>() {
override fun Snapshot<Unit, Unit>.evaluate(): Evaluation<Unit> {
return Evaluation(Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class ActionFormula<Input : Any, Output : Any> : IFormula<Input, Output
abstract fun action(input: Input): Action<Output>

// Implements the common API used by the runtime.
private val implementation = object : Formula<Input, Output, Output>() {
private val implementation: Formula<Input, Output, Output> = object : Formula<Input, Output, Output>() {
override fun initialState(input: Input) = initialValue(input)

override fun Snapshot<Input, Output>.evaluate(): Evaluation<Output> {
Expand Down
4 changes: 2 additions & 2 deletions gradle/merge-reports.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ subprojects { project ->
}

project.plugins.withId("com.android.application") {
disableHtmlTestReport(project)
// disableHtmlTestReport(project)
}

project.plugins.withId("com.android.library") {
disableHtmlTestReport(project)
// disableHtmlTestReport(project)
}
}

Expand Down

0 comments on commit 33f9709

Please sign in to comment.