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/03/01 09:34:14 UTC

[incubator-plc4x] 01/02: added negative test for PlcReader

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

commit ea6c83d93dabf3f30a5c710590758ff598f54f0d
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Mar 1 09:38:01 2018 +0100

    added negative test for PlcReader
---
 .../plc4x/java/api/connection/PlcReaderTest.java     | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/plc4j/api/src/test/java/org/apache/plc4x/java/api/connection/PlcReaderTest.java b/plc4j/api/src/test/java/org/apache/plc4x/java/api/connection/PlcReaderTest.java
index 7ee8660..12abf77 100644
--- a/plc4j/api/src/test/java/org/apache/plc4x/java/api/connection/PlcReaderTest.java
+++ b/plc4j/api/src/test/java/org/apache/plc4x/java/api/connection/PlcReaderTest.java
@@ -19,13 +19,21 @@
 package org.apache.plc4x.java.api.connection;
 
 import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.messages.items.ReadResponseItem;
 import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest;
 import org.apache.plc4x.java.api.model.Address;
+import org.apache.plc4x.java.api.types.ResponseCode;
 import org.junit.Test;
 
 import java.util.Collections;
+import java.util.List;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
 
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
 
 public class PlcReaderTest {
@@ -36,4 +44,16 @@ public class PlcReaderTest {
             .read(new TypeSafePlcReadRequest<>(String.class, mock(Address.class))).get();
     }
 
+    @Test
+    public void readWrongType() throws Exception {
+        try {
+            ((PlcReader) readRequest -> CompletableFuture.completedFuture(new PlcReadResponse(readRequest, (List) Collections.singletonList(new ReadResponseItem(readRequest.getRequestItem().get(), ResponseCode.OK, Collections.singletonList(1))))))
+                .read(new TypeSafePlcReadRequest<>(String.class, mock(Address.class))).get();
+            fail("Should throw an exception");
+        } catch (ExecutionException e) {
+            assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
+            assertThat(e.getCause().getMessage(), equalTo("Unexpected data type class java.lang.Integer on readRequestItem. Expected class java.lang.String"));
+        }
+    }
+
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
sruehl@apache.org.