Skip to content

Commit

Permalink
[ADS-176120] Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdeng2002 committed Dec 1, 2023
1 parent 73f8c1e commit 3744cfc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()
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
Expand Down

0 comments on commit 3744cfc

Please sign in to comment.