Oh. Sorry - I presumed I had to be a committer to do that. I'll consider
it in the future however.
TIA,
--Bill
William McDonald
Sr. Software Developer | TransCentra, Inc.
Office: 1-602-635-5910 | Mobile: 1-602-741-3664 |
william.mcdon...@transcentra.com | www.TransCentra.com
Regulus Group and J&B Software are now TransCentra
This email message is intended for the named recipient only and may be
privileged and/or confidential. If you are not the intended or named
recipient or have received this email in error then you should not copy,
forward or disclose it to any other person. The views and opinions
expressed in this email are those of the sender and may not represent the
views and opinions of TransCentra.
From: "Christian Mueller [via Camel]"
<ml-node+s465427n5716367...@n5.nabble.com>
To: wjmcdonald <william.mcdon...@transcentra.com>
Date: 07/23/2012 02:50 PM
Subject: Re: MockEndpoint expectedBodiesReceived should handle
duplicates
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 <
[hidden email]> 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.
If you reply to this email, your message will be added to the discussion
below:
http://camel.465427.n5.nabble.com/MockEndpoint-expectedBodiesReceived-should-handle-duplicates-tp5716363p5716367.html
To unsubscribe from MockEndpoint expectedBodiesReceived should handle
duplicates, click here.
NAML
--
View this message in context:
http://camel.465427.n5.nabble.com/MockEndpoint-expectedBodiesReceived-should-handle-duplicates-tp5716363p5716417.html
Sent from the Camel - Users mailing list archive at Nabble.com.