This is an automated email from the ASF dual-hosted git repository. sruehl pushed a commit to branch feature/Beckhoff_ADS_protocol in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/feature/Beckhoff_ADS_protocol by this push: new 8e0e8e6 fixed remaining implementations and added tests for it 8e0e8e6 is described below commit 8e0e8e633c3c60ce2c99c062e0cf136da93eddd9 Author: Sebastian Rühl <sru...@apache.org> AuthorDate: Fri Feb 2 11:39:52 2018 +0100 fixed remaining implementations and added tests for it --- .../java/ads/api/commands/types/SampleSize.java | 19 ++++++- .../plc4x/java/ads/api/commands/types/Samples.java | 19 ++++++- .../java/ads/api/commands/types/WriteLength.java | 19 ++++++- .../plc4x/java/ads/api/generic/types/Command.java | 13 +++-- .../java/ads/api/generic/types/DataLength.java | 19 ++++++- .../plc4x/java/ads/api/generic/types/Length.java | 20 +++++++- .../plc4x/java/ads/api/generic/types/State.java | 11 +++- .../apache/plc4x/java/ads/api/util/ByteValue.java | 4 +- .../ads/api/commands/types/SampleSizeTest.java | 58 +++++++++++++++++++++ .../java/ads/api/commands/types/SamplesTest.java | 57 +++++++++++++++++++++ .../ads/api/commands/types/WriteLengthTest.java | 58 +++++++++++++++++++++ .../java/ads/api/generic/types/DataLengthTest.java | 59 ++++++++++++++++++++++ .../java/ads/api/generic/types/LengthTest.java | 57 +++++++++++++++++++++ 13 files changed, 396 insertions(+), 17 deletions(-) diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java index 640cfe5..ff78866 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java @@ -31,11 +31,26 @@ public class SampleSize extends ByteValue { assertLength(NUM_BYTES); } - public static SampleSize of(int size) { - return new SampleSize(ByteBuffer.allocate(NUM_BYTES).putInt(size).array()); + public static SampleSize of(long sampleSize) { + checkUnsignedBounds(sampleSize, NUM_BYTES); + return new SampleSize(ByteBuffer.allocate(NUM_BYTES) + .put((byte) (sampleSize >> 24 & 0xff)) + .put((byte) (sampleSize >> 16 & 0xff)) + .put((byte) (sampleSize >> 8 & 0xff)) + .put((byte) (sampleSize & 0xff)) + .array()); + } + + public static SampleSize of(String sampleSize) { + return of(Long.parseLong(sampleSize)); } public static SampleSize of(byte... values) { return new SampleSize(values); } + + @Override + public String toString() { + return "" + (getBytes()[0] << 24 | getBytes()[1] << 16 | getBytes()[2] << 8 | getBytes()[3]); + } } diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java index 05737d9..2298e00 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java @@ -31,11 +31,26 @@ public class Samples extends ByteValue { assertLength(NUM_BYTES); } - public static Samples of(int numberOfSamples) { - return new Samples(ByteBuffer.allocate(NUM_BYTES).putInt(numberOfSamples).array()); + public static Samples of(long numberOfSamples) { + checkUnsignedBounds(numberOfSamples, NUM_BYTES); + return new Samples(ByteBuffer.allocate(NUM_BYTES) + .put((byte) (numberOfSamples >> 24 & 0xff)) + .put((byte) (numberOfSamples >> 16 & 0xff)) + .put((byte) (numberOfSamples >> 8 & 0xff)) + .put((byte) (numberOfSamples & 0xff)) + .array()); + } + + public static Samples of(String numberOfSamples) { + return of(Long.parseLong(numberOfSamples)); } public static Samples of(byte... values) { return new Samples(values); } + + @Override + public String toString() { + return "" + (getBytes()[0] << 24 | getBytes()[1] << 16 | getBytes()[2] << 8 | getBytes()[3]); + } } diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java index 4920d6e..12931d6 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java @@ -31,11 +31,26 @@ public class WriteLength extends ByteValue { assertLength(NUM_BYTES); } + public static WriteLength of(long length) { + checkUnsignedBounds(length, NUM_BYTES); + return new WriteLength(ByteBuffer.allocate(NUM_BYTES) + .put((byte) (length >> 24 & 0xff)) + .put((byte) (length >> 16 & 0xff)) + .put((byte) (length >> 8 & 0xff)) + .put((byte) (length & 0xff)) + .array()); + } + + public static WriteLength of(String writeLength) { + return of(Long.parseLong(writeLength)); + } + public static WriteLength of(byte... values) { return new WriteLength(values); } - public static WriteLength of(int length) { - return new WriteLength(ByteBuffer.allocate(NUM_BYTES).putInt(length).array()); + @Override + public String toString() { + return "" + (getBytes()[0] << 24 | getBytes()[1] << 16 | getBytes()[2] << 8 | getBytes()[3]); } } diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java index 2424634..1d5db8a 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java @@ -21,6 +21,7 @@ package org.apache.plc4x.java.ads.api.generic.types; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.apache.plc4x.java.ads.api.util.ByteReadable; +import org.apache.plc4x.java.ads.api.util.ByteValue; import java.nio.ByteBuffer; @@ -38,14 +39,20 @@ public enum Command implements ByteReadable { /** * Other commands are not defined or are used internally. Therefore the Command Id is only allowed to contain the above enumerated values! */ - UNKNOWN(0xffff); + UNKNOWN(0xffff_ffff); public static final int NUM_BYTES = 4; final byte[] value; - Command(int value) { - this.value = ByteBuffer.allocate(NUM_BYTES).putInt(value).array(); + Command(long value) { + ByteValue.checkUnsignedBounds(value, NUM_BYTES); + this.value = ByteBuffer.allocate(NUM_BYTES) + .put((byte) (value >> 24 & 0xff)) + .put((byte) (value >> 16 & 0xff)) + .put((byte) (value >> 8 & 0xff)) + .put((byte) (value & 0xff)) + .array(); } @Override diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java index f11c0bd..83d987b 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java @@ -31,11 +31,26 @@ public class DataLength extends ByteValue { assertLength(NUM_BYTES); } + public static DataLength of(long length) { + checkUnsignedBounds(length, NUM_BYTES); + return new DataLength(ByteBuffer.allocate(NUM_BYTES) + .put((byte) (length >> 24 & 0xff)) + .put((byte) (length >> 16 & 0xff)) + .put((byte) (length >> 8 & 0xff)) + .put((byte) (length & 0xff)) + .array()); + } + + public static DataLength of(String length) { + return of(Long.parseLong(length)); + } + public static DataLength of(byte... values) { return new DataLength(values); } - public static DataLength of(int length) { - return new DataLength(ByteBuffer.allocate(NUM_BYTES).putInt(length).array()); + @Override + public String toString() { + return "" + (getBytes()[0] << 24 | getBytes()[1] << 16 | getBytes()[2] << 8 | getBytes()[3]); } } diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java index 6f1f7fb..b0b4363 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java @@ -31,10 +31,26 @@ public class Length extends ByteValue { assertLength(NUM_BYTES); } + public static Length of(long length) { + checkUnsignedBounds(length, NUM_BYTES); + return new Length(ByteBuffer.allocate(NUM_BYTES) + .put((byte) (length >> 24 & 0xff)) + .put((byte) (length >> 16 & 0xff)) + .put((byte) (length >> 8 & 0xff)) + .put((byte) (length & 0xff)) + .array()); + } + + public static Length of(String length) { + return of(Long.parseLong(length)); + } + public static Length of(byte... values) { return new Length(values); } - public static Length of(int length) { - return new Length(ByteBuffer.allocate(NUM_BYTES).putInt(length).array()); + + @Override + public String toString() { + return "" + (getBytes()[0] << 24 | getBytes()[1] << 16 | getBytes()[2] << 8 | getBytes()[3]); } } diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java index 2465bb7..30c93f6 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java @@ -21,6 +21,7 @@ package org.apache.plc4x.java.ads.api.generic.types; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.apache.plc4x.java.ads.api.util.ByteReadable; +import org.apache.plc4x.java.ads.api.util.ByteValue; import java.nio.ByteBuffer; @@ -51,8 +52,14 @@ public enum State implements ByteReadable { final byte[] value; - State(int value) { - this.value = ByteBuffer.allocate(NUM_BYTES).putInt(value).array(); + State(long value) { + ByteValue.checkUnsignedBounds(value, NUM_BYTES); + this.value = ByteBuffer.allocate(NUM_BYTES) + .put((byte) (value >> 24 & 0xff)) + .put((byte) (value >> 16 & 0xff)) + .put((byte) (value >> 8 & 0xff)) + .put((byte) (value & 0xff)) + .array(); } @Override diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteValue.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteValue.java index c45c79b..e500b6f 100644 --- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteValue.java +++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteValue.java @@ -32,13 +32,13 @@ public class ByteValue implements ByteReadable { this.value = value; } - protected void assertLength(int length) { + public void assertLength(int length) { if (value.length != length) { throw new IllegalArgumentException("Expected length " + length + " got " + value.length); } } - protected static void checkUnsignedBounds(long value, int numberOfBytes) { + public static void checkUnsignedBounds(long value, int numberOfBytes) { double upperBound = Math.pow(2, 8 * numberOfBytes); if (value < 0 || value >= upperBound) { throw new IllegalArgumentException("Value must between 0 and " + upperBound + ". Was " + value); diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/SampleSizeTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/SampleSizeTest.java new file mode 100644 index 0000000..db740d0 --- /dev/null +++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/SampleSizeTest.java @@ -0,0 +1,58 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.plc4x.java.ads.api.commands.types; + +import org.apache.commons.codec.binary.Hex; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class SampleSizeTest { + + byte NULL_BYTE = 0x0; + + @Test + void ofBytes() { + Assertions.assertEquals("0", SampleSize.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE).toString()); + Assertions.assertThrows(IllegalArgumentException.class, () -> SampleSize.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE)); + } + + @Test + void ofLong() { + assertByte(SampleSize.of(1), "0x00000001"); + assertByte(SampleSize.of(65535), "0x0000ffff"); + Assertions.assertThrows(IllegalArgumentException.class, () -> SampleSize.of(-1)); + Assertions.assertThrows(IllegalArgumentException.class, () -> SampleSize.of(Long.valueOf("4294967296"))); + } + + @Test + void ofString() { + assertByte(SampleSize.of("1"), "0x00000001"); + } + + @Test + void testToString() { + Assertions.assertEquals(SampleSize.of("1").toString(), "1"); + } + + void assertByte(SampleSize actual, String expected) { + Assertions.assertEquals(expected, "0x" + Hex.encodeHexString(actual.getBytes())); + } + + +} \ No newline at end of file diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/SamplesTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/SamplesTest.java new file mode 100644 index 0000000..82e0b7b --- /dev/null +++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/SamplesTest.java @@ -0,0 +1,57 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.plc4x.java.ads.api.commands.types; + +import org.apache.commons.codec.binary.Hex; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class SamplesTest { + + byte NULL_BYTE = 0x0; + + @Test + void ofBytes() { + Assertions.assertEquals("0", Samples.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE).toString()); + Assertions.assertThrows(IllegalArgumentException.class, () -> Samples.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE)); + } + + @Test + void ofLong() { + assertByte(Samples.of(1), "0x00000001"); + assertByte(Samples.of(65535), "0x0000ffff"); + Assertions.assertThrows(IllegalArgumentException.class, () -> Samples.of(-1)); + Assertions.assertThrows(IllegalArgumentException.class, () -> Samples.of(Long.valueOf("4294967296"))); + } + + @Test + void ofString() { + assertByte(Samples.of("1"), "0x00000001"); + } + + @Test + void testToString() { + Assertions.assertEquals(Samples.of("1").toString(), "1"); + } + + void assertByte(Samples actual, String expected) { + Assertions.assertEquals(expected, "0x" + Hex.encodeHexString(actual.getBytes())); + } + +} \ No newline at end of file diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/WriteLengthTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/WriteLengthTest.java new file mode 100644 index 0000000..633408a --- /dev/null +++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/commands/types/WriteLengthTest.java @@ -0,0 +1,58 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.plc4x.java.ads.api.commands.types; + +import org.apache.commons.codec.binary.Hex; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class WriteLengthTest { + + byte NULL_BYTE = 0x0; + + @Test + void ofBytes() { + Assertions.assertEquals("0", WriteLength.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE).toString()); + Assertions.assertThrows(IllegalArgumentException.class, () -> WriteLength.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE)); + } + + @Test + void ofLong() { + assertByte(WriteLength.of(1), "0x00000001"); + assertByte(WriteLength.of(65535), "0x0000ffff"); + Assertions.assertThrows(IllegalArgumentException.class, () -> WriteLength.of(-1)); + Assertions.assertThrows(IllegalArgumentException.class, () -> WriteLength.of(Long.valueOf("4294967296"))); + } + + @Test + void ofString() { + assertByte(WriteLength.of("1"), "0x00000001"); + } + + @Test + void testToString() { + Assertions.assertEquals(WriteLength.of("1").toString(), "1"); + } + + void assertByte(WriteLength actual, String expected) { + Assertions.assertEquals(expected, "0x" + Hex.encodeHexString(actual.getBytes())); + } + + +} \ No newline at end of file diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/DataLengthTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/DataLengthTest.java new file mode 100644 index 0000000..4d5f8fb --- /dev/null +++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/DataLengthTest.java @@ -0,0 +1,59 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.plc4x.java.ads.api.generic.types; + +import org.apache.commons.codec.binary.Hex; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + + +class DataLengthTest { + + byte NULL_BYTE = 0x0; + + @Test + void ofBytes() { + Assertions.assertEquals("0", DataLength.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE).toString()); + Assertions.assertThrows(IllegalArgumentException.class, () -> DataLength.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE)); + } + + @Test + void ofLong() { + assertByte(DataLength.of(1), "0x00000001"); + assertByte(DataLength.of(65535), "0x0000ffff"); + Assertions.assertThrows(IllegalArgumentException.class, () -> DataLength.of(-1)); + Assertions.assertThrows(IllegalArgumentException.class, () -> DataLength.of(Long.valueOf("4294967296"))); + } + + @Test + void ofString() { + assertByte(DataLength.of("1"), "0x00000001"); + } + + @Test + void testToString() { + Assertions.assertEquals(DataLength.of("1").toString(), "1"); + } + + void assertByte(DataLength actual, String expected) { + Assertions.assertEquals(expected, "0x" + Hex.encodeHexString(actual.getBytes())); + } + + +} \ No newline at end of file diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/LengthTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/LengthTest.java new file mode 100644 index 0000000..19e129e --- /dev/null +++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/LengthTest.java @@ -0,0 +1,57 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.plc4x.java.ads.api.generic.types; + + +import org.apache.commons.codec.binary.Hex; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class LengthTest { + byte NULL_BYTE = 0x0; + + @Test + void ofBytes() { + Assertions.assertEquals("0", Length.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE).toString()); + Assertions.assertThrows(IllegalArgumentException.class, () -> Length.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE)); + } + + @Test + void ofLong() { + assertByte(Length.of(1), "0x00000001"); + assertByte(Length.of(65535), "0x0000ffff"); + Assertions.assertThrows(IllegalArgumentException.class, () -> Length.of(-1)); + Assertions.assertThrows(IllegalArgumentException.class, () -> Length.of(Long.valueOf("4294967296"))); + } + + @Test + void ofString() { + assertByte(Length.of("1"), "0x00000001"); + } + + @Test + void testToString() { + Assertions.assertEquals(Length.of("1").toString(), "1"); + } + + void assertByte(Length actual, String expected) { + Assertions.assertEquals(expected, "0x" + Hex.encodeHexString(actual.getBytes())); + } + +} \ No newline at end of file -- To stop receiving notification emails like this one, please contact sru...@apache.org.