This is an automated email from the ASF dual-hosted git repository. toulmean pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git
The following commit(s) were added to refs/heads/master by this push: new c2bca2e add more tests for bytes new 46e4f3f Merge pull request #135 from atoulme/add_bytes_test c2bca2e is described below commit c2bca2ed25c3f8b24325533015f1e423cf085e6f Author: Antoine Toulme <anto...@lunar-ocean.com> AuthorDate: Sun Jul 19 16:00:33 2020 -0700 add more tests for bytes --- .../tuweni/bytes/DelegateMutableBytes32Test.java | 53 ++++++++++++++++++++++ .../tuweni/bytes/DelegateMutableBytes48Test.java | 53 ++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/bytes/src/test/java/org/apache/tuweni/bytes/DelegateMutableBytes32Test.java b/bytes/src/test/java/org/apache/tuweni/bytes/DelegateMutableBytes32Test.java new file mode 100644 index 0000000..3dda913 --- /dev/null +++ b/bytes/src/test/java/org/apache/tuweni/bytes/DelegateMutableBytes32Test.java @@ -0,0 +1,53 @@ +/* + * 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.tuweni.bytes; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +class DelegateMutableBytes32Test { + + @Test + void failsWhenWrappingArraySmallerThan32() { + Throwable exception = + assertThrows(IllegalArgumentException.class, () -> MutableBytes32.wrap(MutableBytes.wrap(new byte[31]))); + assertEquals("Expected 32 bytes but got 31", exception.getMessage()); + } + + @Test + void failsWhenWrappingArrayLargerThan32() { + Throwable exception = + assertThrows(IllegalArgumentException.class, () -> MutableBytes32.wrap(MutableBytes.wrap(new byte[33]))); + assertEquals("Expected 32 bytes but got 33", exception.getMessage()); + } + + @Test + void testSize() { + assertEquals(32, DelegatingMutableBytes32.delegateTo(MutableBytes32.create()).size()); + } + + @Test + void testCopy() { + Bytes bytes = DelegatingMutableBytes32.delegateTo(MutableBytes32.create()).copy(); + assertEquals(bytes, bytes.copy()); + assertEquals(bytes, bytes.mutableCopy()); + } + + @Test + void testSlice() { + Bytes bytes = DelegatingMutableBytes32.delegateTo(MutableBytes32.create()).copy(); + assertEquals(Bytes.wrap(new byte[] {bytes.get(2), bytes.get(3), bytes.get(4)}), bytes.slice(2, 3)); + } +} diff --git a/bytes/src/test/java/org/apache/tuweni/bytes/DelegateMutableBytes48Test.java b/bytes/src/test/java/org/apache/tuweni/bytes/DelegateMutableBytes48Test.java new file mode 100644 index 0000000..6da5620 --- /dev/null +++ b/bytes/src/test/java/org/apache/tuweni/bytes/DelegateMutableBytes48Test.java @@ -0,0 +1,53 @@ +/* + * 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.tuweni.bytes; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +class DelegateMutableBytes48Test { + + @Test + void failsWhenWrappingArraySmallerThan48() { + Throwable exception = + assertThrows(IllegalArgumentException.class, () -> MutableBytes48.wrap(MutableBytes.wrap(new byte[47]))); + assertEquals("Expected 48 bytes but got 47", exception.getMessage()); + } + + @Test + void failsWhenWrappingArrayLargerThan48() { + Throwable exception = + assertThrows(IllegalArgumentException.class, () -> MutableBytes48.wrap(MutableBytes.wrap(new byte[49]))); + assertEquals("Expected 48 bytes but got 49", exception.getMessage()); + } + + @Test + void testSize() { + assertEquals(48, DelegatingMutableBytes48.delegateTo(MutableBytes48.create()).size()); + } + + @Test + void testCopy() { + Bytes bytes = DelegatingMutableBytes48.delegateTo(MutableBytes48.create()).copy(); + assertEquals(bytes, bytes.copy()); + assertEquals(bytes, bytes.mutableCopy()); + } + + @Test + void testSlice() { + Bytes bytes = DelegatingMutableBytes48.delegateTo(MutableBytes48.create()).copy(); + assertEquals(Bytes.wrap(new byte[] {bytes.get(2), bytes.get(3), bytes.get(4)}), bytes.slice(2, 3)); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@tuweni.apache.org For additional commands, e-mail: commits-h...@tuweni.apache.org