1
1
package org .redisson ;
2
2
3
- import static org .assertj .core .api .Assertions .assertThat ;
4
-
5
- import java .io .Serializable ;
6
- import java .util .AbstractMap ;
7
- import java .util .Arrays ;
8
- import java .util .Collection ;
9
- import java .util .HashMap ;
10
- import java .util .HashSet ;
11
- import java .util .Iterator ;
12
- import java .util .LinkedHashMap ;
13
- import java .util .Map ;
14
- import java .util .Map .Entry ;
15
- import java .util .concurrent .ConcurrentMap ;
16
- import java .util .concurrent .ExecutionException ;
17
- import java .util .concurrent .ThreadLocalRandom ;
18
-
19
- import org .junit .Assert ;
3
+ import org .assertj .core .api .Assertions ;
20
4
import org .junit .Assume ;
21
5
import org .junit .Test ;
22
- import org .redisson .api .RDestroyable ;
23
- import org .redisson .api .RLocalCachedMap ;
24
- import org .redisson .api .RMap ;
25
- import org .redisson .api .RMapCache ;
26
- import org .redisson .api .RedissonClient ;
6
+ import org .redisson .api .*;
27
7
import org .redisson .api .map .MapLoader ;
28
8
import org .redisson .api .map .MapWriter ;
29
9
import org .redisson .client .codec .Codec ;
34
14
import org .redisson .codec .JsonJacksonCodec ;
35
15
import org .redisson .config .Config ;
36
16
17
+ import java .io .Serializable ;
18
+ import java .util .*;
19
+ import java .util .Map .Entry ;
20
+ import java .util .concurrent .ExecutionException ;
21
+ import java .util .concurrent .ThreadLocalRandom ;
22
+
23
+ import static org .assertj .core .api .Assertions .assertThat ;
24
+
37
25
public abstract class BaseMapTest extends BaseTest {
38
26
39
27
public static class SimpleKey implements Serializable {
@@ -237,9 +225,7 @@ public void testStringCodec() {
237
225
rmap .put ("A" , "1" );
238
226
rmap .put ("B" , "2" );
239
227
240
- Iterator <Map .Entry <String , String >> iterator = rmap .entrySet ().iterator ();
241
- while (iterator .hasNext ()) {
242
- Map .Entry <String , String > next = iterator .next ();
228
+ for (Entry <String , String > next : rmap .entrySet ()) {
243
229
assertThat (next ).isIn (new AbstractMap .SimpleEntry ("A" , "1" ), new AbstractMap .SimpleEntry ("B" , "2" ));
244
230
}
245
231
@@ -362,30 +348,30 @@ public void testSize() {
362
348
map .put (new SimpleKey ("1" ), new SimpleValue ("2" ));
363
349
map .put (new SimpleKey ("3" ), new SimpleValue ("4" ));
364
350
map .put (new SimpleKey ("5" ), new SimpleValue ("6" ));
365
- Assert . assertEquals ( 3 , map .size ());
351
+ assertThat ( map .size ()). isEqualTo ( 3 );
366
352
367
353
map .put (new SimpleKey ("1" ), new SimpleValue ("2" ));
368
354
map .put (new SimpleKey ("3" ), new SimpleValue ("4" ));
369
- Assert . assertEquals ( 3 , map .size ());
355
+ assertThat ( map .size ()). isEqualTo ( 3 );
370
356
371
357
map .put (new SimpleKey ("1" ), new SimpleValue ("21" ));
372
358
map .put (new SimpleKey ("3" ), new SimpleValue ("41" ));
373
- Assert . assertEquals ( 3 , map .size ());
359
+ assertThat ( map .size ()). isEqualTo ( 3 );
374
360
375
361
map .put (new SimpleKey ("51" ), new SimpleValue ("6" ));
376
- Assert . assertEquals ( 4 , map .size ());
362
+ assertThat ( map .size ()). isEqualTo ( 4 );
377
363
378
364
map .remove (new SimpleKey ("3" ));
379
- Assert . assertEquals ( 3 , map .size ());
365
+ assertThat ( map .size ()). isEqualTo ( 3 );
380
366
destroy (map );
381
367
}
382
368
383
369
@ Test
384
370
public void testEmptyRemove () {
385
371
RMap <Integer , Integer > map = getMap ("simple" );
386
- Assert . assertFalse (map .remove (1 , 3 ));
372
+ assertThat (map .remove (1 , 3 )). isFalse ( );
387
373
map .put (4 , 5 );
388
- Assert . assertTrue (map .remove (4 , 5 ));
374
+ assertThat (map .remove (4 , 5 )). isTrue ( );
389
375
destroy (map );
390
376
}
391
377
@@ -484,10 +470,10 @@ public void testPutGet() {
484
470
map .put (new SimpleKey ("5" ), new SimpleValue ("6" ));
485
471
486
472
SimpleValue val1 = map .get (new SimpleKey ("33" ));
487
- Assert . assertEquals ( "44" , val1 .getValue ());
473
+ assertThat ( val1 .getValue ()). isEqualTo ( "44" );
488
474
489
475
SimpleValue val2 = map .get (new SimpleKey ("5" ));
490
- Assert . assertEquals ( "6" , val2 .getValue ());
476
+ assertThat ( val2 .getValue ()). isEqualTo ( "6" );
491
477
destroy (map );
492
478
}
493
479
@@ -497,13 +483,13 @@ public void testPutIfAbsent() throws Exception {
497
483
SimpleKey key = new SimpleKey ("1" );
498
484
SimpleValue value = new SimpleValue ("2" );
499
485
map .put (key , value );
500
- Assert . assertEquals ( value , map .putIfAbsent (key , new SimpleValue ("3" )));
501
- Assert . assertEquals ( value , map .get (key ));
486
+ assertThat ( map .putIfAbsent (key , new SimpleValue ("3" ))). isEqualTo ( value );
487
+ assertThat ( map .get (key )). isEqualTo ( value );
502
488
503
489
SimpleKey key1 = new SimpleKey ("2" );
504
490
SimpleValue value1 = new SimpleValue ("4" );
505
- Assert . assertNull (map .putIfAbsent (key1 , value1 ));
506
- Assert . assertEquals ( value1 , map .get (key1 ));
491
+ assertThat (map .putIfAbsent (key1 , value1 )). isNull ( );
492
+ assertThat ( map .get (key1 )). isEqualTo ( value1 );
507
493
destroy (map );
508
494
}
509
495
@@ -513,12 +499,12 @@ public void testDeserializationErrorReturnsErrorImmediately() throws Exception {
513
499
Assume .assumeTrue (!(map instanceof RLocalCachedMap ));
514
500
SimpleObjectWithoutDefaultConstructor object = new SimpleObjectWithoutDefaultConstructor ("test-val" );
515
501
516
- Assert . assertEquals ( "test-val" , object . getTestField () );
502
+ assertThat ( object . getTestField ()). isEqualTo ( "test-val" );
517
503
map .put ("test-key" , object );
518
504
519
505
try {
520
506
map .get ("test-key" );
521
- Assert .fail ("Expected exception from map.get() call" );
507
+ Assertions .fail ("Expected exception from map.get() call" );
522
508
} catch (Exception e ) {
523
509
e .printStackTrace ();
524
510
}
@@ -548,10 +534,10 @@ public void testReplaceOldValueFail() {
548
534
map .put (new SimpleKey ("1" ), new SimpleValue ("2" ));
549
535
550
536
boolean res = map .replace (new SimpleKey ("1" ), new SimpleValue ("43" ), new SimpleValue ("31" ));
551
- Assert . assertFalse (res );
537
+ assertThat (res ). isFalse ( );
552
538
553
539
SimpleValue val1 = map .get (new SimpleKey ("1" ));
554
- Assert . assertEquals ( "2" , val1 .getValue ());
540
+ assertThat ( val1 .getValue ()). isEqualTo ( "2" );
555
541
destroy (map );
556
542
}
557
543
@@ -561,13 +547,13 @@ public void testReplaceOldValueSuccess() {
561
547
map .put (new SimpleKey ("1" ), new SimpleValue ("2" ));
562
548
563
549
boolean res = map .replace (new SimpleKey ("1" ), new SimpleValue ("2" ), new SimpleValue ("3" ));
564
- Assert . assertTrue (res );
550
+ assertThat (res ). isTrue ( );
565
551
566
552
boolean res1 = map .replace (new SimpleKey ("1" ), new SimpleValue ("2" ), new SimpleValue ("3" ));
567
- Assert . assertFalse (res1 );
553
+ assertThat (res1 ). isFalse ( );
568
554
569
555
SimpleValue val1 = map .get (new SimpleKey ("1" ));
570
- Assert . assertEquals ( "3" , val1 .getValue ());
556
+ assertThat ( val1 .getValue ()). isEqualTo ( "3" );
571
557
destroy (map );
572
558
}
573
559
@@ -577,10 +563,10 @@ public void testReplaceValue() {
577
563
map .put (new SimpleKey ("1" ), new SimpleValue ("2" ));
578
564
579
565
SimpleValue res = map .replace (new SimpleKey ("1" ), new SimpleValue ("3" ));
580
- Assert . assertEquals ( "2" , res .getValue ());
566
+ assertThat ( res .getValue ()). isEqualTo ( "2" );
581
567
582
568
SimpleValue val1 = map .get (new SimpleKey ("1" ));
583
- Assert . assertEquals ( "3" , val1 .getValue ());
569
+ assertThat ( val1 .getValue ()). isEqualTo ( "3" );
584
570
destroy (map );
585
571
}
586
572
@@ -593,11 +579,11 @@ public void testReplace() {
593
579
map .put (new SimpleKey ("5" ), new SimpleValue ("6" ));
594
580
595
581
SimpleValue val1 = map .get (new SimpleKey ("33" ));
596
- Assert . assertEquals ( "44" , val1 .getValue ());
582
+ assertThat ( val1 .getValue ()). isEqualTo ( "44" );
597
583
598
584
map .put (new SimpleKey ("33" ), new SimpleValue ("abc" ));
599
585
SimpleValue val2 = map .get (new SimpleKey ("33" ));
600
- Assert . assertEquals ( "abc" , val2 .getValue ());
586
+ assertThat ( val2 .getValue ()). isEqualTo ( "abc" );
601
587
destroy (map );
602
588
}
603
589
@@ -608,9 +594,9 @@ public void testContainsValue() {
608
594
map .put (new SimpleKey ("33" ), new SimpleValue ("44" ));
609
595
map .put (new SimpleKey ("5" ), new SimpleValue ("6" ));
610
596
611
- Assert . assertTrue (map .containsValue (new SimpleValue ("2" )));
612
- Assert . assertFalse (map .containsValue (new SimpleValue ("441" )));
613
- Assert . assertFalse (map .containsValue (new SimpleKey ("5" )));
597
+ assertThat (map .containsValue (new SimpleValue ("2" ))). isTrue ( );
598
+ assertThat (map .containsValue (new SimpleValue ("441" ))). isFalse ( );
599
+ assertThat (map .containsValue (new SimpleKey ("5" ))). isFalse ( );
614
600
destroy (map );
615
601
}
616
602
@@ -621,8 +607,8 @@ public void testContainsKey() {
621
607
map .put (new SimpleKey ("33" ), new SimpleValue ("44" ));
622
608
map .put (new SimpleKey ("5" ), new SimpleValue ("6" ));
623
609
624
- Assert . assertTrue (map .containsKey (new SimpleKey ("33" )));
625
- Assert . assertFalse (map .containsKey (new SimpleKey ("34" )));
610
+ assertThat (map .containsKey (new SimpleKey ("33" ))). isTrue ( );
611
+ assertThat (map .containsKey (new SimpleKey ("34" ))). isFalse ( );
626
612
destroy (map );
627
613
}
628
614
@@ -632,13 +618,13 @@ public void testRemoveValueFail() {
632
618
map .put (new SimpleKey ("1" ), new SimpleValue ("2" ));
633
619
634
620
boolean res = map .remove (new SimpleKey ("2" ), new SimpleValue ("1" ));
635
- Assert . assertFalse (res );
621
+ assertThat (res ). isFalse ( );
636
622
637
623
boolean res1 = map .remove (new SimpleKey ("1" ), new SimpleValue ("3" ));
638
- Assert . assertFalse (res1 );
624
+ assertThat (res1 ). isFalse ( );
639
625
640
626
SimpleValue val1 = map .get (new SimpleKey ("1" ));
641
- Assert . assertEquals ( "2" , val1 .getValue ());
627
+ assertThat ( val1 .getValue ()). isEqualTo ( "2" );
642
628
destroy (map );
643
629
}
644
630
@@ -648,12 +634,12 @@ public void testRemoveValue() {
648
634
map .put (new SimpleKey ("1" ), new SimpleValue ("2" ));
649
635
650
636
boolean res = map .remove (new SimpleKey ("1" ), new SimpleValue ("2" ));
651
- Assert . assertTrue (res );
637
+ assertThat (res ). isTrue ( );
652
638
653
639
SimpleValue val1 = map .get (new SimpleKey ("1" ));
654
- Assert . assertNull (val1 );
640
+ assertThat (val1 ). isNull ( );
655
641
656
- Assert . assertEquals ( 0 , map .size ());
642
+ assertThat ( map .size ()). isZero ( );
657
643
destroy (map );
658
644
}
659
645
@@ -713,7 +699,7 @@ public void testValueIterator() {
713
699
for (Iterator <Integer > iterator = map .values ().iterator (); iterator .hasNext ();) {
714
700
Integer value = iterator .next ();
715
701
if (!values .remove (value )) {
716
- Assert .fail ();
702
+ Assertions .fail ("unable to remove value " + value );
717
703
}
718
704
}
719
705
@@ -724,11 +710,11 @@ public void testValueIterator() {
724
710
@ Test
725
711
public void testFastPut () throws Exception {
726
712
RMap <Integer , Integer > map = getMap ("simple" );
727
- Assert . assertTrue (map .fastPut (1 , 2 ));
713
+ assertThat (map .fastPut (1 , 2 )). isTrue ( );
728
714
assertThat (map .get (1 )).isEqualTo (2 );
729
- Assert . assertFalse (map .fastPut (1 , 3 ));
715
+ assertThat (map .fastPut (1 , 3 )). isFalse ( );
730
716
assertThat (map .get (1 )).isEqualTo (3 );
731
- Assert . assertEquals ( 1 , map .size ());
717
+ assertThat ( map .size ()). isEqualTo ( 1 );
732
718
destroy (map );
733
719
}
734
720
@@ -739,8 +725,8 @@ public void testFastReplace() throws Exception {
739
725
740
726
assertThat (map .fastReplace (1 , 3 )).isTrue ();
741
727
assertThat (map .fastReplace (2 , 0 )).isFalse ();
742
-
743
- Assert . assertEquals ( 1 , map .size ());
728
+
729
+ assertThat ( map .size ()). isEqualTo ( 1 );
744
730
assertThat (map .get (1 )).isEqualTo (3 );
745
731
destroy (map );
746
732
}
@@ -820,7 +806,7 @@ public void testReadAllKeySet() {
820
806
821
807
assertThat (map .readAllKeySet ().size ()).isEqualTo (3 );
822
808
Map <SimpleKey , SimpleValue > testMap = new HashMap <>(map );
823
- assertThat (map .readAllKeySet ()).containsOnlyElementsOf (testMap .keySet ());
809
+ assertThat (map .readAllKeySet ()).isSubsetOf (testMap .keySet ());
824
810
destroy (map );
825
811
}
826
812
@@ -838,9 +824,9 @@ public void testEntrySetIteratorRemoveHighVolume() throws InterruptedException {
838
824
iterator .remove ();
839
825
cnt ++;
840
826
}
841
- Assert . assertEquals (10000 , cnt );
827
+ assertThat ( cnt ). isEqualTo (10000 );
842
828
assertThat (map ).isEmpty ();
843
- Assert . assertEquals ( 0 , map .size ());
829
+ assertThat ( map .size ()). isEqualTo ( 0 );
844
830
destroy (map );
845
831
}
846
832
@@ -862,7 +848,7 @@ public void testEntrySetIteratorRandomRemoveHighVolume() throws InterruptedExcep
862
848
}
863
849
cnt ++;
864
850
}
865
- Assert . assertEquals (10000 , cnt );
851
+ assertThat ( cnt ). isEqualTo (10000 );
866
852
assertThat (map .size ()).isEqualTo (cnt - removed );
867
853
destroy (map );
868
854
}
@@ -881,9 +867,9 @@ public void testKeySetIteratorRemoveHighVolume() throws InterruptedException {
881
867
iterator .remove ();
882
868
cnt ++;
883
869
}
884
- Assert . assertEquals (10000 , cnt );
870
+ assertThat ( cnt ). isEqualTo (10000 );
885
871
assertThat (map ).isEmpty ();
886
- Assert . assertEquals ( 0 , map .size ());
872
+ assertThat ( map .size ()). isEqualTo ( 0 );
887
873
destroy (map );
888
874
}
889
875
@@ -896,7 +882,7 @@ public void testReadAllKeySetHighAmount() {
896
882
897
883
assertThat (map .readAllKeySet ().size ()).isEqualTo (1000 );
898
884
Map <SimpleKey , SimpleValue > testMap = new HashMap <>(map );
899
- assertThat (map .readAllKeySet ()).containsOnlyElementsOf (testMap .keySet ());
885
+ assertThat (map .readAllKeySet ()).isSubsetOf (testMap .keySet ());
900
886
destroy (map );
901
887
}
902
888
@@ -909,7 +895,7 @@ public void testReadAllValues() {
909
895
910
896
assertThat (map .readAllValues ().size ()).isEqualTo (3 );
911
897
Map <SimpleKey , SimpleValue > testMap = new HashMap <>(map );
912
- assertThat (map .readAllValues ()).containsOnlyElementsOf (testMap .values ());
898
+ assertThat (map .readAllValues ()).isSubsetOf (testMap .values ());
913
899
destroy (map );
914
900
}
915
901
0 commit comments