You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/10/06 11:02:05 UTC
[camel] branch main updated: (chores) camel-mock: prevent a few NPEs if there's no exchange at the given index
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 5920bc04070 (chores) camel-mock: prevent a few NPEs if there's no exchange at the given index
5920bc04070 is described below
commit 5920bc04070f624fb25fe3f0821efe6d120ada75
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Oct 4 17:48:43 2022 +0200
(chores) camel-mock: prevent a few NPEs if there's no exchange at the given index
---
.../java/org/apache/camel/component/mock/MockEndpoint.java | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
index a26d72d099c..73c93b8a3c2 100644
--- a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
+++ b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
@@ -591,7 +591,8 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
expects(new AssertionTask() {
@Override
public void assertOnIndex(int i) {
- Exchange exchange = getReceivedExchange(i);
+ final Exchange exchange = getReceivedExchange(i);
+
for (Map.Entry<String, Object> entry : expectedHeaderValues.entrySet()) {
String key = entry.getKey();
Object expectedValue = entry.getValue();
@@ -632,6 +633,7 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
@Override
public void assertOnIndex(int i) {
Exchange exchange = getReceivedExchange(i);
+
assertFalse("Exchange " + i + " has headers", exchange.getIn().hasHeaders());
}
@@ -801,7 +803,6 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
@Override
public void assertOnIndex(int i) {
Exchange exchange = getReceivedExchange(i);
- assertTrue("No exchange received for counter: " + i, exchange != null);
Object expectedBody = expectedBodyValues.get(i);
Object actualBody = null;
@@ -885,7 +886,6 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
public void assertOnIndex(int index) {
if (index == 0) {
Exchange exchange = getReceivedExchange(index);
- assertTrue("No exchange received for counter: " + index, exchange != null);
Object actualBody = exchange.getIn().getBody();
Expression exp = createExpression(getCamelContext());
@@ -920,8 +920,7 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
public void run() {
List<Object> actualBodyValuesSet = new ArrayList<>(actualBodyValues);
for (int i = 0; i < expectedBodyValues.size(); i++) {
- Exchange exchange = getReceivedExchange(i);
- assertTrue("No exchange received for counter: " + i, exchange != null);
+ getReceivedExchange(i);
Object expectedBody = expectedBodyValues.get(i);
assertTrue("Message with body " + expectedBody + " was expected but not found in " + actualBodyValuesSet,
@@ -1888,6 +1887,8 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
if (index <= receivedExchanges.size() - 1) {
return receivedExchanges.get(index);
} else {
+ fail("There is no exchange at index " + index);
+
return null;
}
}