diff --git a/formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt b/formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt index 2920f3ce..f3491342 100644 --- a/formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt +++ b/formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt @@ -1101,33 +1101,37 @@ class FormulaRuntimeTest(val runtime: TestableRuntime, val name: String) { } @Test fun `adding duplicate child throws an exception`() { + val testKey = TestKey("1") val result = Try { val formula = DynamicParentFormula() runtime.test(formula, Unit) - .output { addChild(TestKey("1")) } - .output { addChild(TestKey("1")) } + .output { addChild(testKey) } + .output { addChild(testKey) } } val error = result.errorOrNull()?.cause assertThat(error).isInstanceOf(IllegalStateException::class.java) + assertThat(error?.message).isEqualTo("There already is a child with same key: $testKey. Override [Formula.key] function.") } @Test fun `adding duplicate child logs an exception`() { val logs = mutableListOf() - RxJavaRuntime.setDefaultErrorHandler { logs.add(it.localizedMessage) } + RxJavaRuntime.setDefaultErrorHandler { logs.add(it.message.orEmpty()) } + val testKey = TestKey("1") val result = Try { val formula = DynamicParentFormula() runtime.test(formula, Unit) - .output { addChild(TestKey("1")) } - .output { addChild(TestKey("1")) } + .output { addChild(testKey) } + .output { addChild(testKey) } } val error = result.errorOrNull()?.cause assertThat(error).isNull() assertThat(logs).hasSize(1) val log = logs.first() - assertThat(log).isEqualTo("Duplicate child key: TestKey(id=1)") + assertThat(log).isEqualTo("There already is a child with same key: $testKey. Override [Formula.key] function.") + RxJavaRuntime.setDefaultErrorHandler(null) } @Test