This issue[1] has been fixed few weeks ago.
[1]https://issues.apache.org/jira/browse/CAMEL-5440

On Tue, Jul 24, 2012 at 5:51 AM, Christian Müller <
christian.muel...@gmail.com> wrote:

> Thanks for reporting William!
>
> Do you consider to raise an JIRA [1] and attach your patch?
>
> [1] https://issues.apache.org/jira/browse/CAMEL
>
> Best,
> Christian
>
> On Mon, Jul 23, 2012 at 10:24 PM, wjmcdonald <
> william.mcdon...@transcentra.com> wrote:
>
> > When trying to test bodies received like:
> >     mock.expectedBodiesReceivedInAnyOrder("100000", "400000", "300000",
> > "200000", "400000");
> >
> > The assertMockEndpointsSatisfied() fails because it does not allow
> > duplicate
> > items in the list (eg. two "400000").
> >
> > There is nothing in the javadoc headers that describes the contract these
> > methods have (ie. duplicates allowed or not).  However, I believe that
> > duplicate message bodies allowed is the correct way it should work.
> >
> > Looking at the implementation, the family of expectedBodiesReceivedxxx()
> > use
> > a Set which doesn't allow duplicate items.  The following change to a
> > Multiset fixes the problem.  I don't know if it is threadsafe.
> >
> > (Also, in general, I don't like using 'remove' from collection classes in
> > an
> > iteration as a way of counting things, etc.  I'd prefer an empty
> container
> > that you add to, rather than one that you subtract from.  Perhaps modern
> > Java doesn't have any problems with 'remove()' in a loop anymore, or in
> > this
> > situation since its not using an Iterator.)
> >
> > import com.google.common.collect.HashMultiset;
> > import com.google.common.collect.Multiset;
> >
> >   /**
> >      * Adds an expectation that the given body values are received by
> this
> >      * endpoint in any order
> >      */
> >     public void expectedBodiesReceivedInAnyOrder(final List<?> bodies) {
> >         expectedMessageCount(bodies.size());
> >         this.expectedBodyValues = bodies;
> >         this.actualBodyValues = new ArrayList();
> >
> >         expects(new Runnable() {
> >             public void run() {
> >              /* These two lines changed */
> >                 Multiset actualBodyValuesSet = HashMultiset.create();
> >                 actualBodyValuesSet.addAll(actualBodyValues);
> >                 for (int i = 0; i < expectedBodyValues.size(); i++) {
> >                     Exchange exchange = getReceivedExchange(i);
> >                     assertTrue("No exchange received for counter: " + i,
> > exchange != null);
> >
> >                     Object expectedBody = expectedBodyValues.get(i);
> >                     assertTrue("Message with body " + expectedBody
> >                             + " was expected but not found in " +
> > actualBodyValuesSet,
> >                             actualBodyValuesSet.remove(expectedBody));
> >                 }
> >             }
> >         });
> >     }
> >
> > Can you fix this family of methods to accept duplicates?
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/MockEndpoint-expectedBodiesReceived-should-handle-duplicates-tp5716363.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>

Reply via email to