gnodet commented on code in PR #25554:
URL: https://github.com/apache/camel/pull/25554#discussion_r3856869972


##########
core/camel-core/src/test/java/org/apache/camel/impl/engine/InternalRouteStartupManagerConsumerStartTest.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.engine;
+
+import java.util.Map;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.FailedToStartRouteException;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.DefaultConsumer;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.DefaultProducer;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Verifies that {@link InternalRouteStartupManager} wraps consumer startup 
failures in a
+ * {@link FailedToStartRouteException} with a meaningful (non-null) message, 
even when the root cause carries no message
+ * (e.g. a bare {@link NullPointerException}).
+ *
+ * <p>
+ * Before the fix, the two {@code throw e} sites in {@code 
doStartOrResumeRouteConsumers()} re-threw the raw exception
+ * without any wrapping, causing a bare NPE to escape directly to the caller 
instead of a proper
+ * {@link FailedToStartRouteException}.
+ *
+ * <p>
+ * Reproducer: use a consumer whose {@code start()} throws a message-less 
{@link NullPointerException}, matching the
+ * real-world scenario where e.g. {@code FileConsumer.doStart()} throws NPE 
and it propagates through
+ * {@code BaseService.start()} to {@code 
InternalRouteStartupManager.doStartOrResumeRouteConsumers()} line 429.
+ */
+class InternalRouteStartupManagerConsumerStartTest {
+
+    /**
+     * A bare {@link NullPointerException} (no message) thrown when the 
consumer's {@code start()} is called by
+     * {@link InternalRouteStartupManager} must be wrapped in a {@link 
FailedToStartRouteException} with a non-null
+     * message, not re-thrown as a raw NPE.
+     */
+    @Test
+    void testConsumerStartNullMessageProducesFailedToStartRouteException() 
throws Exception {
+        DefaultCamelContext context = new DefaultCamelContext();
+        context.addComponent("failstart", new ConsumerStartFailComponent(new 
NullPointerException()));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                
from("failstart:trigger").routeId("consumer-start-route").to("direct:out");
+            }
+        });
+
+        FailedToStartRouteException caught = null;
+        try {
+            context.start();
+        } catch (FailedToStartRouteException e) {
+            caught = e;
+        } finally {
+            try {
+                context.stop();
+            } catch (Exception ignored) {
+            }
+        }
+
+        assertNotNull(caught, "Expected FailedToStartRouteException from 
InternalRouteStartupManager — "
+                              + "raw NPE must not escape unwrapped");
+        String message = caught.getMessage();
+        assertNotNull(message, "FailedToStartRouteException message must not 
be null");
+        assertFalse(message.contains("because: null"),
+                "Message must not contain 'because: null' - was: " + message);
+        assertTrue(message.contains("consumer-start-route"),

Review Comment:
   The tests cover the first fix site (consumer start at line ~427 of 
`InternalRouteStartupManager`). The identical fix at the second catch site 
(`routeService.start()` at line ~470) doesn't have a dedicated test. Since both 
sites use the same 5-line pattern and the second path is harder to trigger in 
isolation, this is a minor gap — but worth noting for completeness.



##########
core/camel-core/src/test/java/org/apache/camel/impl/engine/InternalRouteStartupManagerConsumerStartTest.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.engine;
+
+import java.util.Map;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.FailedToStartRouteException;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.DefaultConsumer;
+import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.DefaultProducer;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;

Review Comment:
   Minor style: the test imports JUnit assertions (`assertNotNull`, 
`assertFalse`, `assertTrue`). Per project conventions, new test code should 
prefer AssertJ assertions — e.g., `assertThat(caught).isNotNull()`, 
`assertThat(message).doesNotContain("because: null")`. The try-catch pattern 
could also be replaced with `assertThatThrownBy(() -> 
context.start()).isInstanceOf(FailedToStartRouteException.class).hasMessageContaining("consumer-start-route")`
 for more idiomatic test code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to