gnodet-bot commented on code in PR #29677:
URL: https://github.com/apache/camel/pull/29677#discussion_r4547474658


##########
components/camel-smpp/src/test/java/org/apache/camel/component/smpp/MessageReceiverListenerImplTest.java:
##########
@@ -166,4 +167,33 @@ public void configure() {
             trxContext.stop();
         }
     }
+
+    @Test
+    void aMessageArrivingBeforeInitializationIsRejected() throws Exception {
+        DefaultCamelContext trxContext = new DefaultCamelContext();
+        trxContext.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                
from("direct:messageReceiver").routeId("messageReceiver").process(e -> {
+                });
+            }
+        });
+        when(endpoint.getCamelContext()).thenReturn(trxContext);
+
+        // the context is never started, so the StartupListener never runs and 
consumer/processor stay null
+        MessageReceiverListenerImpl listener = new 
MessageReceiverListenerImpl(endpoint, "messageReceiver");
+
+        try {
+            // makes the bounded wait return at once instead of taking its 
full timeout
+            Thread.currentThread().interrupt();
+
+            ProcessRequestException e
+                    = assertThrows(ProcessRequestException.class, () -> 
listener.onAcceptDeliverSm(deliverSm()));
+            assertTrue(e.getMessage().contains("not initialized"), 
e.getMessage());
+            assertTrue(Thread.currentThread().isInterrupted(), "the interrupt 
flag has to be restored");
+        } finally {
+            // clear the flag so it cannot leak into another test on this 
thread

Review Comment:
   `onAcceptDataSm` has the same `awaitInitialization()` guard and also throws 
`ProcessRequestException` on failure, but the new test only exercises 
`onAcceptDeliverSm`. Add a parallel assertion inside the same test (before the 
`finally`) to cover it:
   
   ```java
   // dataSm follows the same path
   Thread.currentThread().interrupt();
   DataSm dataSm = new DataSm();
   ProcessRequestException e2 = assertThrows(ProcessRequestException.class,
           () -> listener.onAcceptDataSm(dataSm, mock(Session.class)));
   assertTrue(e2.getMessage().contains("not initialized"), e2.getMessage());
   assertTrue(Thread.currentThread().isInterrupted(), "the interrupt flag has 
to be restored");
   Thread.interrupted(); // clear before the next check
   ```
   
   The `alertNotification` path (`return` without throw) is harder to assert 
after the fact, so skipping that is fine — the symmetry between the two 
throwing methods matters more.



-- 
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