Skip to content

Commit d612a05

Browse files
author
Nikita Koksharov
committed
refactoring
1 parent b0b30f3 commit d612a05

File tree

3 files changed

+71
-117
lines changed

3 files changed

+71
-117
lines changed

redisson/src/test/java/org/redisson/BaseMapTest.java

+60-74
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
11
package org.redisson;
22

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;
204
import org.junit.Assume;
215
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.*;
277
import org.redisson.api.map.MapLoader;
288
import org.redisson.api.map.MapWriter;
299
import org.redisson.client.codec.Codec;
@@ -34,6 +14,14 @@
3414
import org.redisson.codec.JsonJacksonCodec;
3515
import org.redisson.config.Config;
3616

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+
3725
public abstract class BaseMapTest extends BaseTest {
3826

3927
public static class SimpleKey implements Serializable {
@@ -237,9 +225,7 @@ public void testStringCodec() {
237225
rmap.put("A", "1");
238226
rmap.put("B", "2");
239227

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()) {
243229
assertThat(next).isIn(new AbstractMap.SimpleEntry("A", "1"), new AbstractMap.SimpleEntry("B", "2"));
244230
}
245231

@@ -362,30 +348,30 @@ public void testSize() {
362348
map.put(new SimpleKey("1"), new SimpleValue("2"));
363349
map.put(new SimpleKey("3"), new SimpleValue("4"));
364350
map.put(new SimpleKey("5"), new SimpleValue("6"));
365-
Assert.assertEquals(3, map.size());
351+
assertThat(map.size()).isEqualTo(3);
366352

367353
map.put(new SimpleKey("1"), new SimpleValue("2"));
368354
map.put(new SimpleKey("3"), new SimpleValue("4"));
369-
Assert.assertEquals(3, map.size());
355+
assertThat(map.size()).isEqualTo(3);
370356

371357
map.put(new SimpleKey("1"), new SimpleValue("21"));
372358
map.put(new SimpleKey("3"), new SimpleValue("41"));
373-
Assert.assertEquals(3, map.size());
359+
assertThat(map.size()).isEqualTo(3);
374360

375361
map.put(new SimpleKey("51"), new SimpleValue("6"));
376-
Assert.assertEquals(4, map.size());
362+
assertThat(map.size()).isEqualTo(4);
377363

378364
map.remove(new SimpleKey("3"));
379-
Assert.assertEquals(3, map.size());
365+
assertThat(map.size()).isEqualTo(3);
380366
destroy(map);
381367
}
382368

383369
@Test
384370
public void testEmptyRemove() {
385371
RMap<Integer, Integer> map = getMap("simple");
386-
Assert.assertFalse(map.remove(1, 3));
372+
assertThat(map.remove(1, 3)).isFalse();
387373
map.put(4, 5);
388-
Assert.assertTrue(map.remove(4, 5));
374+
assertThat(map.remove(4, 5)).isTrue();
389375
destroy(map);
390376
}
391377

@@ -484,10 +470,10 @@ public void testPutGet() {
484470
map.put(new SimpleKey("5"), new SimpleValue("6"));
485471

486472
SimpleValue val1 = map.get(new SimpleKey("33"));
487-
Assert.assertEquals("44", val1.getValue());
473+
assertThat(val1.getValue()).isEqualTo("44");
488474

489475
SimpleValue val2 = map.get(new SimpleKey("5"));
490-
Assert.assertEquals("6", val2.getValue());
476+
assertThat(val2.getValue()).isEqualTo("6");
491477
destroy(map);
492478
}
493479

@@ -497,13 +483,13 @@ public void testPutIfAbsent() throws Exception {
497483
SimpleKey key = new SimpleKey("1");
498484
SimpleValue value = new SimpleValue("2");
499485
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);
502488

503489
SimpleKey key1 = new SimpleKey("2");
504490
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);
507493
destroy(map);
508494
}
509495

@@ -513,12 +499,12 @@ public void testDeserializationErrorReturnsErrorImmediately() throws Exception {
513499
Assume.assumeTrue(!(map instanceof RLocalCachedMap));
514500
SimpleObjectWithoutDefaultConstructor object = new SimpleObjectWithoutDefaultConstructor("test-val");
515501

516-
Assert.assertEquals("test-val", object.getTestField());
502+
assertThat(object.getTestField()).isEqualTo("test-val");
517503
map.put("test-key", object);
518504

519505
try {
520506
map.get("test-key");
521-
Assert.fail("Expected exception from map.get() call");
507+
Assertions.fail("Expected exception from map.get() call");
522508
} catch (Exception e) {
523509
e.printStackTrace();
524510
}
@@ -548,10 +534,10 @@ public void testReplaceOldValueFail() {
548534
map.put(new SimpleKey("1"), new SimpleValue("2"));
549535

550536
boolean res = map.replace(new SimpleKey("1"), new SimpleValue("43"), new SimpleValue("31"));
551-
Assert.assertFalse(res);
537+
assertThat(res).isFalse();
552538

553539
SimpleValue val1 = map.get(new SimpleKey("1"));
554-
Assert.assertEquals("2", val1.getValue());
540+
assertThat(val1.getValue()).isEqualTo("2");
555541
destroy(map);
556542
}
557543

@@ -561,13 +547,13 @@ public void testReplaceOldValueSuccess() {
561547
map.put(new SimpleKey("1"), new SimpleValue("2"));
562548

563549
boolean res = map.replace(new SimpleKey("1"), new SimpleValue("2"), new SimpleValue("3"));
564-
Assert.assertTrue(res);
550+
assertThat(res).isTrue();
565551

566552
boolean res1 = map.replace(new SimpleKey("1"), new SimpleValue("2"), new SimpleValue("3"));
567-
Assert.assertFalse(res1);
553+
assertThat(res1).isFalse();
568554

569555
SimpleValue val1 = map.get(new SimpleKey("1"));
570-
Assert.assertEquals("3", val1.getValue());
556+
assertThat(val1.getValue()).isEqualTo("3");
571557
destroy(map);
572558
}
573559

@@ -577,10 +563,10 @@ public void testReplaceValue() {
577563
map.put(new SimpleKey("1"), new SimpleValue("2"));
578564

579565
SimpleValue res = map.replace(new SimpleKey("1"), new SimpleValue("3"));
580-
Assert.assertEquals("2", res.getValue());
566+
assertThat(res.getValue()).isEqualTo("2");
581567

582568
SimpleValue val1 = map.get(new SimpleKey("1"));
583-
Assert.assertEquals("3", val1.getValue());
569+
assertThat(val1.getValue()).isEqualTo("3");
584570
destroy(map);
585571
}
586572

@@ -593,11 +579,11 @@ public void testReplace() {
593579
map.put(new SimpleKey("5"), new SimpleValue("6"));
594580

595581
SimpleValue val1 = map.get(new SimpleKey("33"));
596-
Assert.assertEquals("44", val1.getValue());
582+
assertThat(val1.getValue()).isEqualTo("44");
597583

598584
map.put(new SimpleKey("33"), new SimpleValue("abc"));
599585
SimpleValue val2 = map.get(new SimpleKey("33"));
600-
Assert.assertEquals("abc", val2.getValue());
586+
assertThat(val2.getValue()).isEqualTo("abc");
601587
destroy(map);
602588
}
603589

@@ -608,9 +594,9 @@ public void testContainsValue() {
608594
map.put(new SimpleKey("33"), new SimpleValue("44"));
609595
map.put(new SimpleKey("5"), new SimpleValue("6"));
610596

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();
614600
destroy(map);
615601
}
616602

@@ -621,8 +607,8 @@ public void testContainsKey() {
621607
map.put(new SimpleKey("33"), new SimpleValue("44"));
622608
map.put(new SimpleKey("5"), new SimpleValue("6"));
623609

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();
626612
destroy(map);
627613
}
628614

@@ -632,13 +618,13 @@ public void testRemoveValueFail() {
632618
map.put(new SimpleKey("1"), new SimpleValue("2"));
633619

634620
boolean res = map.remove(new SimpleKey("2"), new SimpleValue("1"));
635-
Assert.assertFalse(res);
621+
assertThat(res).isFalse();
636622

637623
boolean res1 = map.remove(new SimpleKey("1"), new SimpleValue("3"));
638-
Assert.assertFalse(res1);
624+
assertThat(res1).isFalse();
639625

640626
SimpleValue val1 = map.get(new SimpleKey("1"));
641-
Assert.assertEquals("2", val1.getValue());
627+
assertThat(val1.getValue()).isEqualTo("2");
642628
destroy(map);
643629
}
644630

@@ -648,12 +634,12 @@ public void testRemoveValue() {
648634
map.put(new SimpleKey("1"), new SimpleValue("2"));
649635

650636
boolean res = map.remove(new SimpleKey("1"), new SimpleValue("2"));
651-
Assert.assertTrue(res);
637+
assertThat(res).isTrue();
652638

653639
SimpleValue val1 = map.get(new SimpleKey("1"));
654-
Assert.assertNull(val1);
640+
assertThat(val1).isNull();
655641

656-
Assert.assertEquals(0, map.size());
642+
assertThat(map.size()).isZero();
657643
destroy(map);
658644
}
659645

@@ -713,7 +699,7 @@ public void testValueIterator() {
713699
for (Iterator<Integer> iterator = map.values().iterator(); iterator.hasNext();) {
714700
Integer value = iterator.next();
715701
if (!values.remove(value)) {
716-
Assert.fail();
702+
Assertions.fail("unable to remove value " + value);
717703
}
718704
}
719705

@@ -724,11 +710,11 @@ public void testValueIterator() {
724710
@Test
725711
public void testFastPut() throws Exception {
726712
RMap<Integer, Integer> map = getMap("simple");
727-
Assert.assertTrue(map.fastPut(1, 2));
713+
assertThat(map.fastPut(1, 2)).isTrue();
728714
assertThat(map.get(1)).isEqualTo(2);
729-
Assert.assertFalse(map.fastPut(1, 3));
715+
assertThat(map.fastPut(1, 3)).isFalse();
730716
assertThat(map.get(1)).isEqualTo(3);
731-
Assert.assertEquals(1, map.size());
717+
assertThat(map.size()).isEqualTo(1);
732718
destroy(map);
733719
}
734720

@@ -739,8 +725,8 @@ public void testFastReplace() throws Exception {
739725

740726
assertThat(map.fastReplace(1, 3)).isTrue();
741727
assertThat(map.fastReplace(2, 0)).isFalse();
742-
743-
Assert.assertEquals(1, map.size());
728+
729+
assertThat(map.size()).isEqualTo(1);
744730
assertThat(map.get(1)).isEqualTo(3);
745731
destroy(map);
746732
}
@@ -820,7 +806,7 @@ public void testReadAllKeySet() {
820806

821807
assertThat(map.readAllKeySet().size()).isEqualTo(3);
822808
Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map);
823-
assertThat(map.readAllKeySet()).containsOnlyElementsOf(testMap.keySet());
809+
assertThat(map.readAllKeySet()).isSubsetOf(testMap.keySet());
824810
destroy(map);
825811
}
826812

@@ -838,9 +824,9 @@ public void testEntrySetIteratorRemoveHighVolume() throws InterruptedException {
838824
iterator.remove();
839825
cnt++;
840826
}
841-
Assert.assertEquals(10000, cnt);
827+
assertThat(cnt).isEqualTo(10000);
842828
assertThat(map).isEmpty();
843-
Assert.assertEquals(0, map.size());
829+
assertThat(map.size()).isEqualTo(0);
844830
destroy(map);
845831
}
846832

@@ -862,7 +848,7 @@ public void testEntrySetIteratorRandomRemoveHighVolume() throws InterruptedExcep
862848
}
863849
cnt++;
864850
}
865-
Assert.assertEquals(10000, cnt);
851+
assertThat(cnt).isEqualTo(10000);
866852
assertThat(map.size()).isEqualTo(cnt - removed);
867853
destroy(map);
868854
}
@@ -881,9 +867,9 @@ public void testKeySetIteratorRemoveHighVolume() throws InterruptedException {
881867
iterator.remove();
882868
cnt++;
883869
}
884-
Assert.assertEquals(10000, cnt);
870+
assertThat(cnt).isEqualTo(10000);
885871
assertThat(map).isEmpty();
886-
Assert.assertEquals(0, map.size());
872+
assertThat(map.size()).isEqualTo(0);
887873
destroy(map);
888874
}
889875

@@ -896,7 +882,7 @@ public void testReadAllKeySetHighAmount() {
896882

897883
assertThat(map.readAllKeySet().size()).isEqualTo(1000);
898884
Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map);
899-
assertThat(map.readAllKeySet()).containsOnlyElementsOf(testMap.keySet());
885+
assertThat(map.readAllKeySet()).isSubsetOf(testMap.keySet());
900886
destroy(map);
901887
}
902888

@@ -909,7 +895,7 @@ public void testReadAllValues() {
909895

910896
assertThat(map.readAllValues().size()).isEqualTo(3);
911897
Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map);
912-
assertThat(map.readAllValues()).containsOnlyElementsOf(testMap.values());
898+
assertThat(map.readAllValues()).isSubsetOf(testMap.values());
913899
destroy(map);
914900
}
915901

redisson/src/test/java/org/redisson/RedissonLocalCachedMapSerializationCodecTest.java

-31
This file was deleted.

0 commit comments

Comments
 (0)