Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-7193

Assertions are applied an extra, unnecessary time after an assertion period

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.16.0
    • camel-core
    • None
    • Novice

    Description

      org.apache.camel.component.mock.MockEndpoint.expectedMessagesMatches(Predicate...) is implemented in such a way that, if the test at hand is run with an assert period, then an assertion will be run once before the assert period, but will then be run twice more (when it only needs to run once more) after the assertion period is up.

      This is because the run() method of the org.apache.camel.component.mock.AssertionClause created in expectedMessagesMatches(Predicate...) calls AssertionClause.addPredicate(Predicate), which has not been implemented as an idempotent function.
      Therefore, when the assertion is run before the assert period, the Predicate is added to the AssertionClause once, and when the assertion is run again after the assert period, the same Predicate is added again to the same AssertionClause, and so it is executed one more time than necessary.

      This can be fixed by making the method AssertionClause.addPredicate(Predicate) idempotent. Suggestions for doing so are:

      • to change the type of org.apache.camel.component.mock.AssertionClause.predicates from List<Predicate> to Set<Predicate> (java.util.LinkedHashSet will preserve insertion order), or
      • to add a containment check in AssertionClause.addPredicate(Predicate), before adding the Predicate to the list.

      I am not sure whether this will work with equality checking of anonymous Predicate classes with themselves.

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            arthorbeck Anders Rabo Thorbeck
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified