You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/01/12 14:12:43 UTC
[incubator-plc4x] branch master updated: added some branch coverage
on plc4x producer
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/master by this push:
new 909fd38 added some branch coverage on plc4x producer
909fd38 is described below
commit 909fd388a22e46d70aa10e520b53c4e5acddb27b
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Jan 12 15:12:40 2018 +0100
added some branch coverage on plc4x producer
---
.../org/apache/plc4x/camel/PLC4XProducerTest.java | 43 ++++++++++++++++++----
1 file changed, 36 insertions(+), 7 deletions(-)
diff --git a/integrations/apache-camel/src/test/java/org/apache/plc4x/camel/PLC4XProducerTest.java b/integrations/apache-camel/src/test/java/org/apache/plc4x/camel/PLC4XProducerTest.java
index 614d4a1..15536b0 100644
--- a/integrations/apache-camel/src/test/java/org/apache/plc4x/camel/PLC4XProducerTest.java
+++ b/integrations/apache-camel/src/test/java/org/apache/plc4x/camel/PLC4XProducerTest.java
@@ -21,15 +21,17 @@ package org.apache.plc4x.camel;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.connection.PlcConnection;
import org.apache.plc4x.java.api.connection.PlcWriter;
import org.apache.plc4x.java.api.model.Address;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.List;
import java.util.Optional;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.atomic.AtomicInteger;
import static org.mockito.Mockito.*;
@@ -61,17 +63,25 @@ class PLC4XProducerTest {
SUT.process(testExchange);
when(testExchange.getPattern()).thenReturn(ExchangePattern.OutOnly);
SUT.process(testExchange);
+ when(testExchange.getIn().getBody()).thenReturn(Arrays.asList("test","test"));
+ when(testExchange.getIn().getBody(eq(List.class))).thenReturn(Arrays.asList("test","test"));
+ SUT.process(testExchange);
+
}
@Test
void process_Async() throws Exception {
- SUT.process(testExchange, doneSync -> { });
+ SUT.process(testExchange, doneSync -> {
+ });
when(testExchange.getPattern()).thenReturn(ExchangePattern.InOnly);
- SUT.process(testExchange, doneSync -> { });
+ SUT.process(testExchange, doneSync -> {
+ });
when(testExchange.getPattern()).thenReturn(ExchangePattern.InOut);
- SUT.process(testExchange, doneSync -> { });
+ SUT.process(testExchange, doneSync -> {
+ });
when(testExchange.getPattern()).thenReturn(ExchangePattern.OutOnly);
- SUT.process(testExchange, doneSync -> { });
+ SUT.process(testExchange, doneSync -> {
+ });
}
@Test
@@ -79,4 +89,23 @@ class PLC4XProducerTest {
SUT.doStop();
}
+ @Test
+ void doStopOpenRequest() throws Exception {
+ Field openRequests = SUT.getClass().getDeclaredField("openRequests");
+ openRequests.setAccessible(true);
+ AtomicInteger atomicInteger = (AtomicInteger) openRequests.get(SUT);
+ atomicInteger.incrementAndGet();
+ SUT.doStop();
+ }
+
+ @Test
+ void doStopBadConnection() throws Exception {
+ Field openRequests = SUT.getClass().getDeclaredField("plcConnection");
+ openRequests.setAccessible(true);
+ PlcConnection plcConnectionMock = mock(PlcConnection.class);
+ doThrow(new RuntimeException("oh noes")).when(plcConnectionMock).close();
+ openRequests.set(SUT, plcConnectionMock);
+ SUT.doStop();
+ }
+
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
['"commits@plc4x.apache.org" <co...@plc4x.apache.org>'].