1818package org .apache .hadoop .hbase .util ;
1919
2020import static org .junit .Assert .assertArrayEquals ;
21+ import static org .junit .Assert .assertEquals ;
22+ import static org .junit .Assert .assertFalse ;
23+ import static org .junit .Assert .assertNotNull ;
24+ import static org .junit .Assert .assertNotSame ;
25+ import static org .junit .Assert .assertTrue ;
26+ import static org .junit .Assert .fail ;
27+
2128import java .io .ByteArrayInputStream ;
2229import java .io .ByteArrayOutputStream ;
2330import java .io .DataInputStream ;
3138import java .util .Arrays ;
3239import java .util .List ;
3340import java .util .Random ;
34- import junit .framework .TestCase ;
3541import org .apache .hadoop .hbase .HBaseClassTestRule ;
3642import org .apache .hadoop .hbase .testclassification .MediumTests ;
3743import org .apache .hadoop .hbase .testclassification .MiscTests ;
3844import org .apache .hadoop .io .WritableUtils ;
3945import org .junit .Assert ;
4046import org .junit .ClassRule ;
47+ import org .junit .Test ;
4148import org .junit .experimental .categories .Category ;
4249
4350@ Category ({MiscTests .class , MediumTests .class })
44- public class TestBytes extends TestCase {
51+ public class TestBytes {
4552 @ ClassRule
4653 public static final HBaseClassTestRule CLASS_RULE =
4754 HBaseClassTestRule .forClass (TestBytes .class );
@@ -61,10 +68,12 @@ private static void setUnsafe(boolean value) throws Exception {
6168 assertEquals (Bytes .UNSAFE_UNALIGNED , value );
6269 }
6370
71+ @ Test
6472 public void testShort () throws Exception {
6573 testShort (false );
6674 }
6775
76+ @ Test
6877 public void testShortUnsafe () throws Exception {
6978 testShort (true );
7079 }
@@ -88,6 +97,7 @@ private static void testShort(boolean unsafe) throws Exception {
8897 }
8998 }
9099
100+ @ Test
91101 public void testNullHashCode () {
92102 byte [] b = null ;
93103 Exception ee = null ;
@@ -99,6 +109,7 @@ public void testNullHashCode() {
99109 assertNotNull (ee );
100110 }
101111
112+ @ Test
102113 public void testAdd () {
103114 byte [] a = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 };
104115 byte [] b = {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 };
@@ -112,6 +123,7 @@ public void testAdd() {
112123 assertEquals (0 , Bytes .compareTo (result1 , result2 ));
113124 }
114125
126+ @ Test
115127 public void testSplit () {
116128 byte [] lowest = Bytes .toBytes ("AAA" );
117129 byte [] middle = Bytes .toBytes ("CCC" );
@@ -133,6 +145,7 @@ public void testSplit() {
133145 assertTrue (Bytes .equals (parts [2 ], middle ));
134146 }
135147
148+ @ Test
136149 public void testSplit2 () {
137150 // More split tests.
138151 byte [] lowest = Bytes .toBytes ("http://A" );
@@ -146,6 +159,7 @@ public void testSplit2() {
146159 assertTrue (Bytes .equals (parts [1 ], middle ));
147160 }
148161
162+ @ Test
149163 public void testSplit3 () {
150164 // Test invalid split cases
151165 byte [] low = { 1 , 1 , 1 };
@@ -180,6 +194,7 @@ public void testSplit3() {
180194 }
181195 }
182196
197+ @ Test
183198 public void testToInt () {
184199 int [] ints = { -1 , 123 , Integer .MIN_VALUE , Integer .MAX_VALUE };
185200 for (int anInt : ints ) {
@@ -191,6 +206,7 @@ public void testToInt() {
191206 }
192207 }
193208
209+ @ Test
194210 public void testToLong () {
195211 long [] longs = { -1L , 123L , Long .MIN_VALUE , Long .MAX_VALUE };
196212 for (long aLong : longs ) {
@@ -202,6 +218,7 @@ public void testToLong() {
202218 }
203219 }
204220
221+ @ Test
205222 public void testToFloat () {
206223 float [] floats = { -1f , 123.123f , Float .MAX_VALUE };
207224 for (float aFloat : floats ) {
@@ -212,6 +229,7 @@ public void testToFloat() {
212229 }
213230 }
214231
232+ @ Test
215233 public void testToDouble () {
216234 double [] doubles = {Double .MIN_VALUE , Double .MAX_VALUE };
217235 for (double aDouble : doubles ) {
@@ -222,6 +240,7 @@ public void testToDouble() {
222240 }
223241 }
224242
243+ @ Test
225244 public void testToBigDecimal () {
226245 BigDecimal [] decimals = { new BigDecimal ("-1" ), new BigDecimal ("123.123" ),
227246 new BigDecimal ("123123123123" ) };
@@ -241,6 +260,7 @@ private byte[] bytesWithOffset(byte[] src) {
241260 return result ;
242261 }
243262
263+ @ Test
244264 public void testToBytesForByteBuffer () {
245265 byte [] array = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
246266 ByteBuffer target = ByteBuffer .wrap (array );
@@ -264,6 +284,7 @@ public void testToBytesForByteBuffer() {
264284 assertEquals (5 , target2 .limit ());
265285 }
266286
287+ @ Test
267288 public void testGetBytesForByteBuffer () {
268289 byte [] array = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 };
269290 ByteBuffer target = ByteBuffer .wrap (array );
@@ -277,6 +298,7 @@ public void testGetBytesForByteBuffer() {
277298 assertEquals (7 , target .limit ());
278299 }
279300
301+ @ Test
280302 public void testReadAsVLong () throws Exception {
281303 long [] longs = { -1L , 123L , Long .MIN_VALUE , Long .MAX_VALUE };
282304 for (long aLong : longs ) {
@@ -290,6 +312,7 @@ public void testReadAsVLong() throws Exception {
290312 }
291313 }
292314
315+ @ Test
293316 public void testToStringBinaryForBytes () {
294317 byte [] array = { '0' , '9' , 'a' , 'z' , 'A' , 'Z' , '@' , 1 };
295318 String actual = Bytes .toStringBinary (array );
@@ -301,6 +324,7 @@ public void testToStringBinaryForBytes() {
301324 assertEquals (expected2 , actual2 );
302325 }
303326
327+ @ Test
304328 public void testToStringBinaryForArrayBasedByteBuffer () {
305329 byte [] array = { '0' , '9' , 'a' , 'z' , 'A' , 'Z' , '@' , 1 };
306330 ByteBuffer target = ByteBuffer .wrap (array );
@@ -309,6 +333,7 @@ public void testToStringBinaryForArrayBasedByteBuffer() {
309333 assertEquals (expected , actual );
310334 }
311335
336+ @ Test
312337 public void testToStringBinaryForReadOnlyByteBuffer () {
313338 byte [] array = { '0' , '9' , 'a' , 'z' , 'A' , 'Z' , '@' , 1 };
314339 ByteBuffer target = ByteBuffer .wrap (array ).asReadOnlyBuffer ();
@@ -317,6 +342,7 @@ public void testToStringBinaryForReadOnlyByteBuffer() {
317342 assertEquals (expected , actual );
318343 }
319344
345+ @ Test
320346 public void testBinarySearch () {
321347 byte [][] arr = {
322348 { 1 },
@@ -357,6 +383,7 @@ public void testBinarySearch() {
357383 }
358384 }
359385
386+ @ Test
360387 public void testToStringBytesBinaryReversible () {
361388 // let's run test with 1000 randomly generated byte arrays
362389 Random rand = new Random (EnvironmentEdgeManager .currentTime ());
@@ -381,6 +408,7 @@ private void verifyReversibleForBytes(byte[] originalBytes) {
381408 }
382409 }
383410
411+ @ Test
384412 public void testStartsWith () {
385413 assertTrue (Bytes .startsWith (Bytes .toBytes ("hello" ), Bytes .toBytes ("h" )));
386414 assertTrue (Bytes .startsWith (Bytes .toBytes ("hello" ), Bytes .toBytes ("" )));
@@ -389,6 +417,7 @@ public void testStartsWith() {
389417 assertFalse (Bytes .startsWith (Bytes .toBytes ("" ), Bytes .toBytes ("hello" )));
390418 }
391419
420+ @ Test
392421 public void testIncrementBytes () {
393422 assertTrue (checkTestIncrementBytes (10 , 1 ));
394423 assertTrue (checkTestIncrementBytes (12 , 123435445 ));
@@ -423,6 +452,7 @@ private static boolean checkTestIncrementBytes(long val, long amount) {
423452 return (Bytes .toLong (testValue ) + amount ) == incrementResult ;
424453 }
425454
455+ @ Test
426456 public void testFixedSizeString () throws IOException {
427457 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
428458 DataOutputStream dos = new DataOutputStream (baos );
@@ -448,13 +478,15 @@ public void testFixedSizeString() throws IOException {
448478 assertEquals ("" , Bytes .readStringFixedSize (dis , 9 ));
449479 }
450480
481+ @ Test
451482 public void testCopy () {
452483 byte [] bytes = Bytes .toBytes ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
453484 byte [] copy = Bytes .copy (bytes );
454485 assertNotSame (bytes , copy );
455486 assertTrue (Bytes .equals (bytes , copy ));
456487 }
457488
489+ @ Test
458490 public void testToBytesBinaryTrailingBackslashes () {
459491 try {
460492 Bytes .toBytesBinary ("abc\\ x00\\ x01\\ " );
@@ -463,11 +495,13 @@ public void testToBytesBinaryTrailingBackslashes() {
463495 }
464496 }
465497
498+ @ Test
466499 public void testToStringBinary_toBytesBinary_Reversable () {
467500 String bytes = Bytes .toStringBinary (Bytes .toBytes (2.17 ));
468501 assertEquals (2.17 , Bytes .toDouble (Bytes .toBytesBinary (bytes )), 0 );
469502 }
470503
504+ @ Test
471505 public void testUnsignedBinarySearch (){
472506 byte [] bytes = new byte [] { 0 ,5 ,123 ,127 ,-128 ,-100 ,-1 };
473507 Assert .assertEquals (1 , Bytes .unsignedBinarySearch (bytes , 0 , bytes .length , (byte )5 ));
@@ -479,6 +513,7 @@ public void testUnsignedBinarySearch(){
479513 Assert .assertEquals (-6 -1 , Bytes .unsignedBinarySearch (bytes , 0 , bytes .length , (byte )-5 ));
480514 }
481515
516+ @ Test
482517 public void testUnsignedIncrement (){
483518 byte [] a = Bytes .toBytes (0 );
484519 int a2 = Bytes .toInt (Bytes .unsignedCopyAndIncrement (a ), 0 );
@@ -495,6 +530,7 @@ public void testUnsignedIncrement(){
495530 Assert .assertEquals (256 , c2 );
496531 }
497532
533+ @ Test
498534 public void testIndexOf () {
499535 byte [] array = Bytes .toBytes ("hello" );
500536 assertEquals (1 , Bytes .indexOf (array , (byte ) 'e' ));
@@ -505,6 +541,7 @@ public void testIndexOf() {
505541 assertEquals (-1 , Bytes .indexOf (array , Bytes .toBytes ("hll" )));
506542 }
507543
544+ @ Test
508545 public void testContains () {
509546 byte [] array = Bytes .toBytes ("hello world" );
510547 assertTrue (Bytes .contains (array , (byte ) 'e' ));
@@ -515,6 +552,7 @@ public void testContains() {
515552 assertFalse (Bytes .contains (array , Bytes .toBytes ("owo" )));
516553 }
517554
555+ @ Test
518556 public void testZero () {
519557 byte [] array = Bytes .toBytes ("hello" );
520558 Bytes .zero (array );
@@ -533,6 +571,7 @@ public void testZero() {
533571 }
534572 }
535573
574+ @ Test
536575 public void testPutBuffer () {
537576 byte [] b = new byte [100 ];
538577 for (byte i = 0 ; i < 100 ; i ++) {
@@ -543,6 +582,7 @@ public void testPutBuffer() {
543582 }
544583 }
545584
585+ @ Test
546586 public void testToFromHex () {
547587 List <String > testStrings = new ArrayList <>(8 );
548588 testStrings .addAll (Arrays .asList ("" , "00" , "A0" , "ff" , "FFffFFFFFFFFFF" , "12" ,
0 commit comments