Croway commented on code in PR #21306:
URL: https://github.com/apache/camel/pull/21306#discussion_r2783882281
##########
components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XConsumerTest.java:
##########
@@ -16,17 +16,66 @@
*/
package org.apache.camel.component.plc4x;
+import java.util.Collections;
+import java.util.concurrent.ScheduledFuture;
+
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-// TODO: implement me
-public class Plc4XConsumerTest {
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+class Plc4XConsumerTest {
+
+ private Plc4XEndpoint endpoint;
+ private Processor processor;
+ private Plc4XConsumer consumer;
+
+ @BeforeEach
+ void setUp() {
+ endpoint = mock(Plc4XEndpoint.class);
+ processor = mock(Processor.class);
+
+ when(endpoint.getTags()).thenReturn(Collections.emptyMap());
+ when(endpoint.getTrigger()).thenReturn(null); // untriggered
+ when(endpoint.getCamelContext()).thenReturn(new DefaultCamelContext());
+
+ consumer = new Plc4XConsumer(endpoint, processor);
+ }
+
+ @Test
+ void doStart() throws Exception {
+ doNothing().when(endpoint).setupConnection();
+
+ consumer.doStart();
+
+ verify(endpoint, times(1)).setupConnection();
+ }
@Test
- public void doStart() {
+ void doStartBadStart() throws Exception {
+ doThrow(new PlcConnectionException("fail"))
+ .when(endpoint).setupConnection();
+
+ consumer.doStart();
+
+ verify(endpoint).setupConnection();
+ assertFalse(consumer.isStarted());
}
@Test
- public void doStop() {
+ void doStop() throws Exception {
+ ScheduledFuture<?> future = mock(ScheduledFuture.class);
+ var field = Plc4XConsumer.class.getDeclaredField("future");
Review Comment:
is reflection really needed?
Is there another way to test it maybe?
--
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]