From 33f9709e2891eaf089b8842fcf622d2fb21aa9d7 Mon Sep 17 00:00:00 2001 From: Laimonas Turauskas Date: Thu, 4 Jan 2024 16:44:47 -0500 Subject: [PATCH] Fix mocking of action formula. (#331) --- .../com/instacart/formula/MockitoFormulaTest.kt | 16 ++++++++++++++++ .../java/com/instacart/formula/ActionFormula.kt | 2 +- gradle/merge-reports.gradle | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/formula-android/src/test/java/com/instacart/formula/MockitoFormulaTest.kt b/formula-android/src/test/java/com/instacart/formula/MockitoFormulaTest.kt index 3aba8e80..940711ed 100644 --- a/formula-android/src/test/java/com/instacart/formula/MockitoFormulaTest.kt +++ b/formula-android/src/test/java/com/instacart/formula/MockitoFormulaTest.kt @@ -16,12 +16,28 @@ class MockitoFormulaTest { assertThat(formula.type()).isEqualTo(MyFormula::class) } + @Test fun mockActionFormula() { + val testFormula = ReplacementFormula().implementation() + val formula = mock(defaultAnswer = CallsRealMethods()) + whenever(formula.implementation()).thenReturn(testFormula) + assertThat(formula.implementation()).isEqualTo(testFormula) + assertThat(formula.type()).isEqualTo(MyActionFormula::class) + } + class MyFormula : StatelessFormula() { override fun Snapshot.evaluate(): Evaluation { return Evaluation(Unit) } } + class MyActionFormula : ActionFormula() { + override fun initialValue(input: Unit) = Unit + + override fun action(input: Unit): Action { + return Action.onData(Unit) + } + } + class ReplacementFormula : StatelessFormula() { override fun Snapshot.evaluate(): Evaluation { return Evaluation(Unit) diff --git a/formula/src/main/java/com/instacart/formula/ActionFormula.kt b/formula/src/main/java/com/instacart/formula/ActionFormula.kt index be7a4f8c..9eb52a9a 100644 --- a/formula/src/main/java/com/instacart/formula/ActionFormula.kt +++ b/formula/src/main/java/com/instacart/formula/ActionFormula.kt @@ -18,7 +18,7 @@ abstract class ActionFormula : IFormula // Implements the common API used by the runtime. - private val implementation = object : Formula() { + private val implementation: Formula = object : Formula() { override fun initialState(input: Input) = initialValue(input) override fun Snapshot.evaluate(): Evaluation { diff --git a/gradle/merge-reports.gradle b/gradle/merge-reports.gradle index 3aa6c075..9cbd01e7 100644 --- a/gradle/merge-reports.gradle +++ b/gradle/merge-reports.gradle @@ -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) } }