2828
2929import static org .junit .Assert .*;
3030
31- public class MutableBytesABytesTest extends ABytesTest {
31+ public class MutableBytesTest extends ABytesTest {
3232 @ Test
33- public void overwriteWithEmptyArray () throws Exception {
33+ public void overwriteWithEmptyArray () {
3434 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
3535 assertSame (b , b .overwrite (new byte [example_bytes_seven .length ]));
3636 assertArrayEquals (new byte [example_bytes_seven .length ], b .array ());
3737 }
3838
3939 @ Test
40- public void overwriteOtherArray () throws Exception {
40+ public void overwriteOtherArray () {
4141 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
4242 assertSame (b , b .overwrite (Arrays .copyOf (example2_bytes_seven , example2_bytes_seven .length )));
4343 assertArrayEquals (example2_bytes_seven , b .array ());
4444 }
4545
4646 @ Test
47- public void overwritePartialArray () throws Exception {
47+ public void overwritePartialArray () {
4848 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
4949 assertSame (b , b .overwrite (new byte []{(byte ) 0xAA }, 0 ));
5050 assertArrayEquals (Bytes .from ((byte ) 0xAA ).append (Bytes .wrap (example_bytes_seven ).copy (1 , example_bytes_seven .length - 1 )).array (), b .array ());
5151 }
5252
5353 @ Test
54- public void overwritePartialArray2 () throws Exception {
54+ public void overwritePartialArray2 () {
5555 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
5656 assertSame (b , b .overwrite (new byte []{(byte ) 0xAA }, 1 ));
5757 assertArrayEquals (
@@ -62,14 +62,44 @@ public void overwritePartialArray2() throws Exception {
6262 }
6363
6464 @ Test
65- public void fill () throws Exception {
65+ public void fill () {
6666 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
6767 assertSame (b , b .fill ((byte ) 0 ));
6868 assertArrayEquals (new byte [example_bytes_seven .length ], b .array ());
6969 }
7070
7171 @ Test
72- public void setByteAtTest () throws Exception {
72+ public void testConvertImmutable () {
73+ Bytes b = Bytes .from (example_bytes_seven );
74+ MutableBytes m = b .copy ().mutable ();
75+ assertNotEquals (b , m );
76+ assertTrue (b .equalsContent (m ));
77+ assertEquals (b .byteOrder (), m .byteOrder ());
78+
79+ Bytes m2b = m .immutable ();
80+ assertNotEquals (m2b , m );
81+ assertEquals (m2b , b );
82+ assertNotSame (m2b , b );
83+ assertTrue (m2b .equalsContent (m ));
84+ assertEquals (m2b .byteOrder (), m .byteOrder ());
85+
86+ assertEquals (m .length (), m2b .length ());
87+ assertEquals (m .length (), b .length ());
88+
89+ assertNotEquals (example_bytes_seven [0 ], 0 );
90+ assertEquals (example_bytes_seven [0 ], b .byteAt (0 ));
91+ assertEquals (example_bytes_seven [0 ], m .byteAt (0 ));
92+ assertEquals (example_bytes_seven [0 ], m2b .byteAt (0 ));
93+
94+ m .fill ((byte ) 0 );
95+
96+ assertEquals (example_bytes_seven [0 ], b .byteAt (0 ));
97+ assertEquals (0 , m .byteAt (0 ));
98+ assertEquals (0 , m2b .byteAt (0 ));
99+ }
100+
101+ @ Test
102+ public void setByteAtTest () {
73103 MutableBytes b = fromAndTest (example_bytes_sixteen ).mutable ();
74104
75105 for (int i = 0 ; i < b .length (); i ++) {
@@ -82,14 +112,14 @@ public void setByteAtTest() throws Exception {
82112 }
83113
84114 @ Test
85- public void wipe () throws Exception {
115+ public void wipe () {
86116 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
87117 assertSame (b , b .wipe ());
88118 assertArrayEquals (new byte [example_bytes_seven .length ], b .array ());
89119 }
90120
91121 @ Test
92- public void secureWipe () throws Exception {
122+ public void secureWipe () {
93123 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
94124 int hashcode = b .hashCode ();
95125 assertSame (b , b .secureWipe ());
@@ -99,7 +129,7 @@ public void secureWipe() throws Exception {
99129 }
100130
101131 @ Test
102- public void secureWipeWithSecureRandom () throws Exception {
132+ public void secureWipeWithSecureRandom () {
103133 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
104134 int hashcode = b .hashCode ();
105135 assertSame (b , b .secureWipe (new SecureRandom ()));
@@ -109,18 +139,18 @@ public void secureWipeWithSecureRandom() throws Exception {
109139 }
110140
111141 @ Test (expected = NullPointerException .class )
112- public void secureWipeShouldThrowException () throws Exception {
142+ public void secureWipeShouldThrowException () {
113143 Bytes .wrap (new byte [0 ]).mutable ().secureWipe (null );
114144 }
115145
116146 @ Test
117- public void testIfGetSameInstance () throws Exception {
147+ public void testIfGetSameInstance () {
118148 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
119149 assertSame (b , b .mutable ());
120150 }
121151
122152 @ Test
123- public void testTransformerShouldBeMutable () throws Exception {
153+ public void testTransformerShouldBeMutable () {
124154 MutableBytes b = fromAndTest (example_bytes_seven ).mutable ();
125155 assertTrue (b .isMutable ());
126156 assertTrue (b .copy ().isMutable ());
@@ -137,4 +167,4 @@ public void testTransformerShouldBeMutable() throws Exception {
137167 assertTrue (b .append (3 ).isMutable ());
138168 assertTrue (b .hashSha256 ().isMutable ());
139169 }
140- }
170+ }
0 commit comments