diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt index 9ebdc449f2..4133facd42 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt @@ -1,20 +1,40 @@ +// TODO 1.0.0 at the latest: use type ExplanatoryGroup.FinalStep when ExplanatoryAssertionGroupFinalStep is removed +@file:Suppress("DEPRECATION") + package ch.tutteli.atrium.logic.creating.collectors import ch.tutteli.atrium.assertions.AssertionGroup import ch.tutteli.atrium.assertions.ExplanatoryAssertionGroupType import ch.tutteli.atrium.assertions.builders.AssertionsOption +import ch.tutteli.atrium.assertions.builders.ExplanatoryAssertionGroupFinalStep +import ch.tutteli.atrium.core.None import ch.tutteli.atrium.core.Option import ch.tutteli.atrium.creating.AssertionContainer +import ch.tutteli.atrium.creating.CollectingExpect import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.creating.ExperimentalComponentFactoryContainer import ch.tutteli.atrium.logic.collectForCompositionBasedOnSubject /** * Collects the assertions [assertionCreator] creates and uses them as [AssertionGroup.assertions]. * * //TODO 0.18.0 in case we somehow incorporate the current container in AssertionsOptions, then remove container as parameter + * + * TODO 1.0.0 at the latest: use type ExplanatoryGroup.FinalStep when ExplanatoryAssertionGroupFinalStep is removed */ -fun AssertionsOption.collectAssertions( +@Suppress("DEPRECATION" /* OptIn is only available since 1.3.70 which we cannot use if we want to support 1.2 */) +@UseExperimental(ExperimentalComponentFactoryContainer::class) +fun AssertionsOption.collectAssertions( container: AssertionContainer<*>, maybeSubject: Option, assertionCreator: Expect.() -> Unit -): R = withAssertions(container.collectForCompositionBasedOnSubject(maybeSubject, assertionCreator)) +): ExplanatoryAssertionGroupFinalStep { + val collectingExpect = CollectingExpect(None, container.components) + // not using addAssertionsCreatedBy on purpose so that we don't append a failing assertion + collectingExpect.assertionCreator() + return withAssertions(container.collectForCompositionBasedOnSubject(maybeSubject, assertionCreator)) + .let { + if(collectingExpect.getAssertions().isEmpty()) it.failing + else it + } +} diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/iterable/contains/creators/impl/InAnyOrderEntriesAssertionCreator.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/iterable/contains/creators/impl/InAnyOrderEntriesAssertionCreator.kt index 87a4d35462..797686d20c 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/iterable/contains/creators/impl/InAnyOrderEntriesAssertionCreator.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/iterable/contains/creators/impl/InAnyOrderEntriesAssertionCreator.kt @@ -94,8 +94,6 @@ class InAnyOrderEntriesAssertionCreator( val featureAssertion = featureFactory(count, DescriptionIterableAssertion.NUMBER_OF_OCCURRENCES) val assertions = mutableListOf(explanatoryGroup) if (searchBehaviour is NotSearchBehaviour) { - createEmptyAssertionHintIfNecessary(multiConsumableContainer, searchCriterion, count) - ?.let { assertions.add(it) } val mismatches = createIndexAssertions(list) { (_, element) -> allCreatedAssertionsHold(multiConsumableContainer, element, searchCriterion) } @@ -118,27 +116,4 @@ class InAnyOrderEntriesAssertionCreator( val count = list.count { allCreatedAssertionsHold(container, it, assertionCreatorOrNull) } return group to count } - - //TODO 0.18.0 check if this is still state of the art to add a hint that no assertion was created - // in the assertionCreator-lambda, maybe it is a special case and needs to be handled like this, - // maybe it would be enough to collect - @Suppress("DEPRECATION" /* OptIn is only available since 1.3.70 which we cannot use if we want to support 1.2 */) - @UseExperimental(ExperimentalComponentFactoryContainer::class) - private fun createEmptyAssertionHintIfNecessary( - container: AssertionContainer<*>, - searchCriterion: (Expect.() -> Unit)?, - count: Int - ): Assertion? { - if (searchCriterion != null && count == 0) { - val collectingExpect = CollectingExpect(None, container.components) - // not using addAssertionsCreatedBy on purpose so that we don't append a failing assertion - collectingExpect.searchCriterion() - val collectedAssertions = collectingExpect.getAssertions() - if (collectedAssertions.isEmpty()) { - // no assertion created in the lambda, so return the failing assertion containing the hint - return container.collectBasedOnSubject(None, searchCriterion) - } - } - return null - } }