diff --git a/src/main/kotlin/com/flo/nem12/handler/CompositeFailureHandler.kt b/src/main/kotlin/com/flo/nem12/handler/CompositeFailureHandler.kt index 6584521..5676740 100644 --- a/src/main/kotlin/com/flo/nem12/handler/CompositeFailureHandler.kt +++ b/src/main/kotlin/com/flo/nem12/handler/CompositeFailureHandler.kt @@ -26,16 +26,8 @@ class CompositeFailureHandler( } override fun getStatistics(): Map { - // Aggregate statistics from all handlers - val aggregated = mutableMapOf() - - handlers.forEach { handler -> - handler.getStatistics().forEach { (reason, count) -> - aggregated[reason] = aggregated.getOrDefault(reason, 0) + count - } - } - - return aggregated + // Return statistics from the first handler to avoid double counting + return handlers.firstOrNull()?.getStatistics() ?: emptyMap() } override fun close() { diff --git a/src/test/kotlin/com/flo/nem12/handler/CompositeFailureHandlerTest.kt b/src/test/kotlin/com/flo/nem12/handler/CompositeFailureHandlerTest.kt index 2df3da5..959263f 100644 --- a/src/test/kotlin/com/flo/nem12/handler/CompositeFailureHandlerTest.kt +++ b/src/test/kotlin/com/flo/nem12/handler/CompositeFailureHandlerTest.kt @@ -35,7 +35,7 @@ class CompositeFailureHandlerTest { } @Test - fun `should aggregate statistics from multiple handlers`() { + fun `should return statistics from first handler`() { // Given val handler1 = LoggingFailureHandler() val handler2 = LoggingFailureHandler() @@ -65,10 +65,10 @@ class CompositeFailureHandlerTest { compositeHandler.handleFailure(failure1) compositeHandler.handleFailure(failure2) - // Then - Statistics should be aggregated from both handlers + // Then - Statistics should come from first handler only (to avoid double counting) val stats = compositeHandler.getStatistics() - assertEquals(2, stats[FailureReason.NEGATIVE_VALUE]) // Each handler counted once - assertEquals(2, stats[FailureReason.EMPTY_VALUE]) + assertEquals(1, stats[FailureReason.NEGATIVE_VALUE]) + assertEquals(1, stats[FailureReason.EMPTY_VALUE]) // Clean up compositeHandler.close()