Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C1A29CC7D for ; Mon, 23 Jul 2012 21:51:46 +0000 (UTC) Received: (qmail 46279 invoked by uid 500); 23 Jul 2012 21:51:46 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 46250 invoked by uid 500); 23 Jul 2012 21:51:46 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 46242 invoked by uid 99); 23 Jul 2012 21:51:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2012 21:51:46 +0000 X-ASF-Spam-Status: No, hits=2.8 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of christian.mueller@gmail.com designates 209.85.217.173 as permitted sender) Received: from [209.85.217.173] (HELO mail-lb0-f173.google.com) (209.85.217.173) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2012 21:51:40 +0000 Received: by lbok6 with SMTP id k6so10394701lbo.32 for ; Mon, 23 Jul 2012 14:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ozToX9EaboJzHPPJiZCyOpcB5M7G613uVlor7XoXG9w=; b=gpVgnQZa9ij5CZZG/ZD9JRxaaahLo20tNb4IBCk5MshcjTue99WNqdjKbbbHL8saOa YMzl7pE35XPkrEM8ulrNlA0PUvpg4gtKCHa1RDijmhYpvQyFxb2ixf6RqJ2judcMqksy 3GB1AOo5Q9vlMvnqN0NsrFmO3yEz83vFQ/M/d5Y1MN0kCc2KHpUUd2McJAzh2pZzC1xP c2XwLMTM05aDg0tE7N+tkc/IXRzr8M1e3wDuwFsLiOY6GHeFCorcawAYdH42uGg6uZmW 0TyRTlxDI4Pj+0Tl3qvAy9lqncwb2K430K29hjXvlvdINEwfXadqq2/prUC9HRFe9fGe X6VA== MIME-Version: 1.0 Received: by 10.112.83.229 with SMTP id t5mr8575561lby.8.1343080279442; Mon, 23 Jul 2012 14:51:19 -0700 (PDT) Received: by 10.114.14.1 with HTTP; Mon, 23 Jul 2012 14:51:19 -0700 (PDT) In-Reply-To: <1343075087414-5716363.post@n5.nabble.com> References: <1343075087414-5716363.post@n5.nabble.com> Date: Mon, 23 Jul 2012 23:51:19 +0200 Message-ID: Subject: Re: MockEndpoint expectedBodiesReceived should handle duplicates From: =?ISO-8859-1?Q?Christian_M=FCller?= To: users@camel.apache.org Content-Type: multipart/alternative; boundary=f46d04016d9df604c504c5863ef5 --f46d04016d9df604c504c5863ef5 Content-Type: text/plain; charset=ISO-8859-1 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.mcdonald@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. > --f46d04016d9df604c504c5863ef5--