@@ -67,14 +67,19 @@ public void wrapTest() {
6767 assertEquals (0 , bNullSafe1 .length ());
6868 }
6969
70+ @ Test (expected = NullPointerException .class )
71+ public void wrapByteNull_shouldThrow () {
72+ Bytes .wrap ((Bytes ) null );
73+ }
74+
7075 @ Test (expected = NullPointerException .class )
7176 public void wrapTestNullExpected () {
7277 Bytes .wrap ((byte []) null );
7378 }
7479
7580 @ Test
7681 public void wrapTestNullSafe () {
77- Bytes .wrapNullSafe (null );
82+ assertSame ( Bytes .empty (), Bytes . wrapNullSafe (null ) );
7883 }
7984
8085 @ Test
@@ -183,6 +188,11 @@ public void fromInt() {
183188 assertEquals (test , Bytes .from (test ).toInt ());
184189 }
185190
191+ @ Test (expected = NullPointerException .class )
192+ public void fromIntArray_empty_shouldThrow () {
193+ Bytes .from ((int []) null );
194+ }
195+
186196 @ Test
187197 public void fromIntArray () {
188198 assertArrayEquals (new byte []{0 , 0 , 0 , 1 , 0 , 0 , 0 , 2 }, Bytes .from (1 , 2 ).array ());
@@ -207,6 +217,11 @@ public void fromLong() {
207217 assertEquals (test , Bytes .from (test ).toLong ());
208218 }
209219
220+ @ Test (expected = NullPointerException .class )
221+ public void fromLongArray_empty_shouldThrow () {
222+ Bytes .from ((long []) null );
223+ }
224+
210225 @ Test
211226 public void fromLongArray () {
212227 assertArrayEquals (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 }, Bytes .from (new long []{1 , 2 }).array ());
@@ -224,6 +239,22 @@ public void fromFloat() {
224239 assertEquals (test , Bytes .from (test ).toFloat (), 0.01 );
225240 }
226241
242+ @ Test (expected = NullPointerException .class )
243+ public void fromFloatArray_empty_shouldThrow () {
244+ Bytes .from ((float []) null );
245+ }
246+
247+ @ Test
248+ public void fromFloatArray () {
249+ assertArrayEquals (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, Bytes .from (0f , 0f ).array ());
250+ assertArrayEquals (new byte []{0 , 0 , 0 , 0 , 63 , -128 , 0 , 0 }, Bytes .from (0f , 1f ).array ());
251+ assertArrayEquals (new byte []{0 , 0 , 0 , 0 , -65 , -128 , 0 , 0 }, Bytes .from (0f , -1f ).array ());
252+ assertArrayEquals (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, Bytes .from (0f , 0f , 0f ).array ());
253+ assertArrayEquals (new byte []{66 , -105 , 0 , 0 , 71 , 119 , 46 , 31 }, Bytes .from (75.5f , 63278.123f ).array ());
254+ assertArrayEquals (Bytes .from (Bytes .from (78239.934978f ), Bytes .from (-82736.65178f ), Bytes .from (0.12879316287461f )).array (),
255+ Bytes .from (78239.934978f , -82736.65178f , 0.12879316287461f ).array ());
256+ }
257+
227258 @ Test
228259 public void fromDouble () {
229260 double test = 3423423.8923423974123 ;
@@ -233,6 +264,21 @@ public void fromDouble() {
233264 assertEquals (test , Bytes .from (test ).toDouble (), 0.01 );
234265 }
235266
267+ @ Test (expected = NullPointerException .class )
268+ public void fromDoubleArray_empty_shouldThrow () {
269+ Bytes .from ((double []) null );
270+ }
271+
272+ @ Test
273+ public void fromDoubleArray () {
274+ assertArrayEquals (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, Bytes .from (0.0 , 0.0 ).array ());
275+ assertArrayEquals (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 63 , -16 , 0 , 0 , 0 , 0 , 0 , 0 }, Bytes .from (0.0 , 1.0 ).array ());
276+ assertArrayEquals (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -65 , -16 , 0 , 0 , 0 , 0 , 0 , 0 }, Bytes .from (0.0 , -1.0 ).array ());
277+ assertArrayEquals (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, Bytes .from (0 , 0 , 0 ).array ());
278+ assertArrayEquals (Bytes .from (Bytes .from (78239.934978 ), Bytes .from (-82736.65178 ), Bytes .from (0.12879316287461 )).array (),
279+ Bytes .from (78239.934978 , -82736.65178 , 0.12879316287461 ).array ());
280+ }
281+
236282 @ Test
237283 public void fromByteBuffer () {
238284 checkByteBuffer (example_bytes_empty );
@@ -325,6 +371,11 @@ public void toCharArrayShouldThroughNullPointer() {
325371 Bytes .allocate (4 ).toCharArray (null );
326372 }
327373
374+ @ Test (expected = NullPointerException .class )
375+ public void fromMultipleBytes_empty_shouldThrow () {
376+ Bytes .from ((Bytes []) null );
377+ }
378+
328379 @ Test
329380 public void fromMultipleBytes () {
330381 assertArrayEquals (new byte []{0x01 , 0x02 , 0x03 }, Bytes .from (Bytes .from ((byte ) 0x01 ), Bytes .from ((byte ) 0x02 ), Bytes .from ((byte ) 0x03 )).array ());
@@ -446,6 +497,21 @@ public void fromVariousBytes() {
446497 assertArrayEquals (example_bytes_sixteen , Bytes .fromNullSafe (example_bytes_sixteen ).array ());
447498 }
448499
500+ @ Test (expected = NullPointerException .class )
501+ public void fromArray_empty_shouldThrow () {
502+ Bytes .from ((byte []) null );
503+ }
504+
505+ @ Test (expected = NullPointerException .class )
506+ public void wrapArrayByteOrder_empty_shouldThrow () {
507+ Bytes .wrap (null , ByteOrder .BIG_ENDIAN );
508+ }
509+
510+ @ Test (expected = NullPointerException .class )
511+ public void fromPartByte_empty_shouldThrow () {
512+ Bytes .from ((byte []) null , 0 , 1 );
513+ }
514+
449515 @ Test
450516 public void fromPartByte () {
451517 assertArrayEquals (new byte []{example_bytes_four [1 ]}, Bytes .from (example_bytes_four , 1 , 1 ).array ());
0 commit comments