@@ -67,7 +67,7 @@ public void appendMulti() throws Exception {
6767 }
6868
6969 @ Test
70- public void resizeGrow () throws Exception {
70+ public void resizeGrowLsb () throws Exception {
7171 assertArrayEquals (new byte [8 ], Bytes .from (new byte [0 ]).resize (8 ).array ());
7272 assertArrayEquals (example_bytes_one , Bytes .from (example_bytes_one ).resize (1 ).array ());
7373 assertArrayEquals (example_bytes_one , Bytes .from (example_bytes_one ).resize (1 ).array ());
@@ -77,7 +77,17 @@ public void resizeGrow() throws Exception {
7777 }
7878
7979 @ Test
80- public void resizeShrink () throws Exception {
80+ public void resizeGrowMsb () throws Exception {
81+ assertArrayEquals (new byte [8 ], Bytes .from (new byte [0 ]).resize (8 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
82+ assertArrayEquals (example_bytes_one , Bytes .from (example_bytes_one ).resize (1 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
83+ assertArrayEquals (example_bytes_one , Bytes .from (example_bytes_one ).resize (1 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
84+ assertArrayEquals (Util .concat (example_bytes_one , new byte [7 ]), Bytes .from (example_bytes_one ).resize (8 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
85+ assertArrayEquals (Util .concat (example_bytes_seven , new byte [1 ]), Bytes .from (example_bytes_seven ).resize (8 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
86+ assertArrayEquals (Util .concat (example_bytes_sixteen , new byte [1 ]), Bytes .from (example_bytes_sixteen ).resize (17 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
87+ }
88+
89+ @ Test
90+ public void resizeShrinkLsb () throws Exception {
8191 assertArrayEquals (new byte [0 ], Bytes .from (example_bytes_one ).resize (0 ).array ());
8292 assertArrayEquals (new byte []{example_bytes_two [1 ]}, Bytes .from (example_bytes_two ).resize (1 ).array ());
8393 assertArrayEquals (new byte []{example_bytes_four [3 ]}, Bytes .from (example_bytes_four ).resize (1 ).array ());
@@ -89,8 +99,21 @@ public void resizeShrink() throws Exception {
8999 try {
90100 Bytes .from (new byte [0 ]).resize (-1 );
91101 fail ();
92- } catch (IllegalArgumentException e ) {
102+ } catch (IllegalArgumentException ignore ) {
103+ }
104+ }
93105
106+ @ Test
107+ public void resizeShrinkMsb () throws Exception {
108+ assertArrayEquals (new byte [0 ], Bytes .from (example_bytes_one ).resize (0 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
109+ assertArrayEquals (new byte []{example_bytes_two [0 ]}, Bytes .from (example_bytes_two ).resize (1 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
110+ assertArrayEquals (new byte []{example_bytes_four [0 ]}, Bytes .from (example_bytes_four ).resize (1 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
111+ assertArrayEquals (new byte []{example_bytes_four [0 ], example_bytes_four [1 ]}, Bytes .from (example_bytes_four ).resize (2 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX ).array ());
112+
113+ try {
114+ Bytes .from (new byte [0 ]).resize (-1 , BytesTransformer .ResizeTransformer .Mode .RESIZE_KEEP_FROM_ZERO_INDEX );
115+ fail ();
116+ } catch (IllegalArgumentException ignore ) {
94117 }
95118 }
96119
@@ -142,7 +165,7 @@ public void or() throws Exception {
142165 try {
143166 Bytes .from (example_bytes_seven ).or (example_bytes_eight );
144167 fail ();
145- } catch (Exception e ) {
168+ } catch (Exception ignore ) {
146169 }
147170 }
148171
@@ -162,7 +185,7 @@ public void and() throws Exception {
162185 try {
163186 Bytes .from (example_bytes_seven ).and (example_bytes_eight );
164187 fail ();
165- } catch (Exception e ) {
188+ } catch (Exception ignore ) {
166189 }
167190 }
168191
@@ -355,7 +378,7 @@ public void transformerInPlaceTest() throws Exception {
355378
356379 assertFalse (new BytesTransformer .MessageDigestTransformer ("SHA1" ).supportInPlaceTransformation ());
357380 assertFalse (new BytesTransformer .CopyTransformer (0 , 0 ).supportInPlaceTransformation ());
358- assertFalse (new BytesTransformer .ResizeTransformer (0 ).supportInPlaceTransformation ());
381+ assertFalse (new BytesTransformer .ResizeTransformer (0 , BytesTransformer . ResizeTransformer . Mode . RESIZE_KEEP_FROM_MAX_LENGTH ).supportInPlaceTransformation ());
359382 assertFalse (new BytesTransformer .ConcatTransformer (new byte []{}).supportInPlaceTransformation ());
360383
361384 assertFalse (new BytesTransformers .GzipCompressor (false ).supportInPlaceTransformation ());
0 commit comments