You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by fm...@apache.org on 2026/02/11 16:19:25 UTC
(camel) 04/04: removed usage of reflection.
This is an automated email from the ASF dual-hosted git repository.
fmariani pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8b22e94a425f325c8ea266a92dd580321af34dd7
Author: chandrashekhar <ch...@gmail.com>
AuthorDate: Tue Feb 10 22:01:13 2026 +0530
removed usage of reflection.
---
.../camel/component/plc4x/Plc4XConsumerTest.java | 31 +++++++++++++---------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XConsumerTest.java b/components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XConsumerTest.java
index 9cddb32cfc1a..b44a9a44a1e7 100644
--- a/components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XConsumerTest.java
+++ b/components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XConsumerTest.java
@@ -17,7 +17,7 @@
package org.apache.camel.component.plc4x;
import java.util.Collections;
-import java.util.concurrent.ScheduledFuture;
+import java.util.Map;
import org.apache.camel.Processor;
import org.apache.camel.impl.DefaultCamelContext;
@@ -48,34 +48,41 @@ class Plc4XConsumerTest {
@Test
void doStart() throws Exception {
- doNothing().when(endpoint).setupConnection();
+ doNothing().when(endpoint).setupConnection();
consumer.doStart();
-
verify(endpoint, times(1)).setupConnection();
}
@Test
void doStartBadStart() throws Exception {
+
doThrow(new PlcConnectionException("fail"))
.when(endpoint).setupConnection();
-
consumer.doStart();
-
verify(endpoint).setupConnection();
assertFalse(consumer.isStarted());
}
@Test
- void doStop() throws Exception {
- ScheduledFuture<?> future = mock(ScheduledFuture.class);
- var field = Plc4XConsumer.class.getDeclaredField("future");
- field.setAccessible(true);
- field.set(consumer, future);
+ void shouldStartTriggeredScraperWhenTriggerPresent() throws Exception {
- consumer.doStop();
+ when(endpoint.getTrigger()).thenReturn("someTrigger");
+ when(endpoint.getTags()).thenReturn(Map.of("tag1", "value1"));
+ when(endpoint.getPeriod()).thenReturn(1000);
+ when(endpoint.getUri()).thenReturn("mock:plc");
- verify(future).cancel(true);
+ // Avoid real connection
+ doNothing().when(endpoint).setupConnection();
+ doNothing().when(endpoint).reconnectIfNeeded();
+ when(endpoint.createExchange()).thenReturn(mock(org.apache.camel.Exchange.class));
+ consumer.doStart();
+ verify(endpoint, atLeastOnce()).getTrigger();
+ }
+
+ @Test
+ void doStop() throws Exception {
+ consumer.doStop();
}
}