This is an automated email from the ASF dual-hosted git repository.

jmclean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit bef900c3d035b9170d57d35ba12a5a82f60d92aa
Author: Justin Mclean <jmcl...@apache.org>
AuthorDate: Sun Feb 25 14:04:22 2018 +1100

    Next unit tests (some just for coverage)
---
 .../java/ads/api/generic/types/AMSErrorTest.java   | 80 ++++++++++++++++++++++
 .../java/ads/api/generic/types/AMSNetIdTest.java   | 42 ++++++++++++
 .../java/ads/api/generic/types/CommandTest.java    | 39 +++++++++++
 .../java/ads/api/generic/types/StateTest.java      | 41 +++++++++++
 .../plc4x/java/ads/model/ADSAddressTest.java       | 40 +++++++++++
 5 files changed, 242 insertions(+)

diff --git 
a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/AMSErrorTest.java
 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/AMSErrorTest.java
new file mode 100644
index 0000000..0e08d4e
--- /dev/null
+++ 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/AMSErrorTest.java
@@ -0,0 +1,80 @@
+package org.apache.plc4x.java.ads.api.generic.types;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+
+public class AMSErrorTest {
+
+    @Test
+    public void errorBytes() {
+        // note bytes in reverse order
+        AMSError error = AMSError.of((byte)0x01, (byte)0x20, (byte)0x00, 
(byte)0x00);
+        assertThat(error.getAsLong(), is(0x2001L));
+    }
+
+    @Test
+    public void errorLong() {
+        AMSError error = AMSError.of(0xFF02L);
+        assertThat(error.getAsLong(), is(0xFF02L));
+    }
+
+    @Test
+    public void errorLongBig() {
+        AMSError error = AMSError.of(0xFFFFFFFFL);
+        assertThat(error.getAsLong(), is(0xFFFFFFFFL));
+    }
+    
+    @Test
+    public void errorString() {
+        AMSError error = AMSError.of("255");
+        assertThat(error.getAsLong(), is(0xFFL));
+    }
+
+    @Test
+    public void errorByteBuf() {
+        ByteBuf buffer = Unpooled.buffer();
+
+        // note bytes in reverse order
+        buffer.writeByte((byte)0x04);
+        buffer.writeByte((byte)0x01);
+        buffer.writeByte((byte)0x00);
+        buffer.writeByte((byte)0x00);
+
+        AMSError error = AMSError.of(buffer);
+        assertThat(error.getAsLong(), is(260L));
+    }
+
+    @Test(expected = NumberFormatException.class)
+    public void noHex() {
+        AMSError error = AMSError.of("0xFF000000");
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void errorLongTooBig() {
+        AMSError error = AMSError.of(0x100000000L);
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void errorNegative() {
+        AMSError error = AMSError.of(-1);
+    }
+    
+    @Test
+    public void equals() {
+        AMSError a = AMSError.of((byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 
0x4);
+        AMSError b = AMSError.of((byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 
0x4);
+        AMSError c = AMSError.of((byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 
0xFF);
+        byte array[] = {(byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4};
+
+        assertThat(a.equals(a), is(true));
+        assertThat(a.equals(b), is(true));
+        assertThat(a.equals(c), is(false));
+        assertThat(a.equals(1), is(false));
+        assertThat(a.equals((byte) 1), is(false));
+        assertThat(a.equals(array), is(false));
+    }
+}
\ No newline at end of file
diff --git 
a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetIdTest.java
 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetIdTest.java
new file mode 100644
index 0000000..0942c18
--- /dev/null
+++ 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetIdTest.java
@@ -0,0 +1,42 @@
+package org.apache.plc4x.java.ads.api.generic.types;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+
+public class AMSNetIdTest {
+
+    @Test
+    public void netIdBytes() {
+        // note bytes in reverse order
+        AMSNetId netid = AMSNetId.of((byte)0x01, (byte)0x02, (byte)0x03, 
(byte)0x04, (byte)0x05, (byte)0x06);
+        assertThat(netid.toString(), is("1.2.3.4.5.6"));
+    }
+
+    @Test
+    public void netIdString() {
+        // note bytes in reverse order
+        AMSNetId netid = AMSNetId.of("1.2.3.4.5.6");
+        assertThat(netid.toString(), is("1.2.3.4.5.6"));
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void netIdTooShort() {
+        // note bytes in reverse order
+        AMSNetId netid = AMSNetId.of("1.2.3.4");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void netIdStringTooLong() {
+        // note bytes in reverse order
+        AMSNetId netid = AMSNetId.of("1.2.3.4.5.6.7.8");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void netIdStringWrongSeperator() {
+        // note bytes in reverse order
+        AMSNetId netid = AMSNetId.of("1:2:3:4:5:6");
+    }
+
+}
\ No newline at end of file
diff --git 
a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/CommandTest.java
 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/CommandTest.java
new file mode 100644
index 0000000..d8b5a8e
--- /dev/null
+++ 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/CommandTest.java
@@ -0,0 +1,39 @@
+package org.apache.plc4x.java.ads.api.generic.types;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+
+public class CommandTest {
+
+    @Test
+    public void getBytes() {
+        byte[] result = {(byte)0x01, (byte)0x00};
+        Command command = Command.ofInt("1");
+        assertThat(command.getBytes(), is(result));
+    }
+
+    @Test
+    public void getByteBuf() {
+        ByteBuf result = Unpooled.buffer();
+        result.writeByte(0x02);
+        result.writeByte(0x00);
+        Command command = Command.ofInt("2");
+        assertThat(command.getByteBuf(), is(result));
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void getBytesUnknown() {
+        Command command = Command.UNKNOWN;
+        command.getBytes();
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void getByteBufUnknown() {
+        Command command = Command.UNKNOWN;
+        command.getByteBuf();
+    }
+}
\ No newline at end of file
diff --git 
a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/StateTest.java
 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/StateTest.java
new file mode 100644
index 0000000..ebe5ae4
--- /dev/null
+++ 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/StateTest.java
@@ -0,0 +1,41 @@
+package org.apache.plc4x.java.ads.api.generic.types;
+
+import org.junit.Test;
+
+import java.util.EnumSet;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.isEmptyString;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.*;
+
+public class StateTest {
+
+    // Not the best unit tests but here for coverage
+
+    @Test
+    public void stateBitFields() {
+        int bitMask = State.StateMask.RESPONSE.getMask() | 
State.StateMask.NO_RETURN.getMask() | State.StateMask.ADS_COMMAND.getMask()
+                        | State.StateMask.SYSTEM_COMMAND.getMask() | 
State.StateMask.HIGH_PRIORITY_COMMAND.getMask() | 
State.StateMask.TIMESTAMP_ADDED.getMask()
+                        | State.StateMask.UDP_COMMAND.getMask() | 
State.StateMask.INIT_COMMAND.getMask() | State.StateMask.BROADCAST.getMask();
+        State state = State.of(bitMask);
+
+        assertThat(state.toString(), not((isEmptyString())));
+    }
+
+    @Test
+    public void equals() {
+        State a = State.of((byte) 0x1, (byte) 0x2);
+        State b = State.of((byte) 0x1, (byte) 0x2);
+        State c = State.of((byte) 0x1, (byte) 0x4);
+        byte array[] = {(byte) 0x1, (byte) 0x2};
+
+        assertThat(a.equals(a), is(true));
+        assertThat(a.equals(b), is(true));
+        assertThat(a.equals(c), is(false));
+        assertThat(a.equals(1), is(false));
+        assertThat(a.equals((byte) 1), is(false));
+        assertThat(a.equals(array), is(false));
+    }
+
+}
\ No newline at end of file
diff --git 
a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/model/ADSAddressTest.java
 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/model/ADSAddressTest.java
new file mode 100644
index 0000000..67970f2
--- /dev/null
+++ 
b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/model/ADSAddressTest.java
@@ -0,0 +1,40 @@
+package org.apache.plc4x.java.ads.model;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+
+public class ADSAddressTest {
+
+    @Test
+    public void of() {
+        ADSAddress address = ADSAddress.of("1/10");
+        assertThat(address.getIndexGroup(), is(1L));
+        assertThat(address.getIndexOffset(), is(10L));
+    }
+
+    @Test(expected  = IllegalArgumentException.class)
+    public void stringInAddress() {
+        ADSAddress address = ADSAddress.of("group/offset");
+    }
+
+    @Test(expected  = IllegalArgumentException.class)
+    public void singleNumberAddress() {
+        ADSAddress address = ADSAddress.of("10");
+    }
+
+    @Test(expected  = IllegalArgumentException.class)
+    public void wrongSeperator() {
+        ADSAddress address = ADSAddress.of("1:10");
+    }
+
+    @Test
+    public void getGroupAndOffset() {
+        ADSAddress address = ADSAddress.of(2L, 20L);
+        assertThat(address.getIndexGroup(), is(2L));
+        assertThat(address.getIndexOffset(), is(20L));
+    }
+}
\ No newline at end of file

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

Reply via email to