3131import static org .junit .Assert .*;
3232
3333public class MutableBytesTest extends ABytesTest {
34+ @ Test
35+ public void allocate () {
36+ MutableBytes b = MutableBytes .allocate (8 );
37+ assertEquals (8 , b .length ());
38+ assertFalse (b .validateNotOnlyZeros ());
39+ }
40+
41+ @ Test
42+ public void allocateFill () {
43+ MutableBytes b = MutableBytes .allocate (1 , (byte ) 0xFF );
44+ assertEquals (1 , b .length ());
45+ assertEquals ((byte ) 0xFF , b .byteAt (0 ));
46+ }
47+
3448 @ Test
3549 public void overwriteWithEmptyArray () {
3650 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
@@ -45,6 +59,13 @@ public void overwriteOtherArray() {
4559 assertArrayEquals (example2_bytes_seven , b .array ());
4660 }
4761
62+ @ Test
63+ public void overwriteOtherBytesInstance () {
64+ MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
65+ assertSame (b , b .overwrite (Bytes .from (example2_bytes_seven )));
66+ assertArrayEquals (example2_bytes_seven , b .array ());
67+ }
68+
4869 @ Test
4970 public void overwritePartialArray () {
5071 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
@@ -66,9 +87,9 @@ public void overwritePartialArray2() {
6687 @ Test
6788 public void overwriteBytes () {
6889 MutableBytes a = fromAndTest (example_bytes_seven ).mutable ();
69- MutableBytes b = Bytes .from ((byte )0 ).mutable ();
90+ MutableBytes b = Bytes .from ((byte ) 0 ).mutable ();
7091 MutableBytes c = a .overwrite (b , 0 ).mutable ();
71- MutableBytes d = Bytes .wrap (a ).copy (1 , a .array ().length - 1 ).mutable ();
92+ MutableBytes d = Bytes .wrap (a ).copy (1 , a .array ().length - 1 ).mutable ();
7293
7394 assertArrayEquals (c .array (), Bytes .from (b ).append (d ).array ());
7495 }
@@ -79,7 +100,8 @@ public void overwriteTooBigArrayShouldThrowException() {
79100 try {
80101 b .overwrite (new byte []{(byte ) 0xAA , 0x30 }, b .length ());
81102 fail ();
82- } catch (IndexOutOfBoundsException ignored ) {}
103+ } catch (IndexOutOfBoundsException ignored ) {
104+ }
83105
84106 }
85107
@@ -89,7 +111,8 @@ public void overwriteTooBigBytesShouldThrowException() {
89111 try {
90112 b .overwrite (Bytes .from ((byte ) 0xAA , 0x30 ), b .length ());
91113 fail ();
92- } catch (IndexOutOfBoundsException ignored ) {}
114+ } catch (IndexOutOfBoundsException ignored ) {
115+ }
93116
94117 }
95118
@@ -98,10 +121,11 @@ public void overwriteNullArrayShouldThrowException() {
98121 MutableBytes nonsense = null ;
99122 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
100123
101- try {
124+ try {
102125 b .overwrite (nonsense );
103126 fail ();
104- } catch (NullPointerException ignored ){}
127+ } catch (NullPointerException ignored ) {
128+ }
105129
106130
107131 }
0 commit comments