Skip to content

Commit c72a848

Browse files
committed
DATAREDIS-1196 - Polishing.
Tweak Redis 6.0.6 requirement wording. Join assertions where possible and use more concise assertions. Original pull request: #563.
1 parent 76cbe51 commit c72a848

File tree

7 files changed

+36
-43
lines changed

7 files changed

+36
-43
lines changed

src/main/java/org/springframework/data/redis/connection/RedisListCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum Position {
4949

5050
/**
5151
* Returns the index of matching elements inside the list stored at given {@literal key}. <br />
52-
* Requires Redis 6.0.6.
52+
* Requires Redis 6.0.6 or newer.
5353
*
5454
* @param key must not be {@literal null}.
5555
* @param element must not be {@literal null}.
@@ -64,7 +64,7 @@ default Long lPos(byte[] key, byte[] element) {
6464

6565
/**
6666
* Returns the index of matching elements inside the list stored at given {@literal key}. <br />
67-
* Requires Redis 6.0.6.
67+
* Requires Redis 6.0.6 or newer.
6868
*
6969
* @param key must not be {@literal null}.
7070
* @param element must not be {@literal null}.

src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ default Long bitPos(String key, boolean bit) {
688688

689689
/**
690690
* Returns the index of matching elements inside the list stored at given {@literal key}. <br />
691-
* Requires Redis 6.0.6.
691+
* Requires Redis 6.0.6 or newer.
692692
*
693693
* @param key must not be {@literal null}.
694694
* @param element must not be {@literal null}.
@@ -703,7 +703,7 @@ default Long lPos(String key, String element) {
703703

704704
/**
705705
* Returns the index of matching elements inside the list stored at given {@literal key}. <br />
706-
* Requires Redis 6.0.6.
706+
* Requires Redis 6.0.6 or newer.
707707
*
708708
* @param key must not be {@literal null}.
709709
* @param element must not be {@literal null}.
@@ -2059,7 +2059,7 @@ default RecordId xAdd(StringRecord record) {
20592059

20602060
/**
20612061
* Append the given {@link StringRecord} to the stream stored at {@link StringRecord#getStream()}.
2062-
*
2062+
*
20632063
* @param record must not be {@literal null}.
20642064
* @param options must not be {@literal null}, use {@link XAddOptions#none()} instead.
20652065
* @return the record Id. {@literal null} when used in pipeline / transaction.

src/main/java/org/springframework/data/redis/core/BoundListOperations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {
171171

172172
/**
173173
* Returns the index of the first occurrence of the specified value in the list at at {@code key}. <br />
174-
* Requires Redis 6.0.6
174+
* Requires Redis 6.0.6 or newer.
175175
*
176176
* @param value must not be {@literal null}.
177177
* @return {@literal null} when used in pipeline / transaction or when not contained in list.
@@ -182,7 +182,7 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {
182182

183183
/**
184184
* Returns the index of the last occurrence of the specified value in the list at at {@code key}. <br />
185-
* Requires Redis 6.0.6
185+
* Requires Redis 6.0.6 or newer.
186186
*
187187
* @param value must not be {@literal null}.
188188
* @return {@literal null} when used in pipeline / transaction or when not contained in list.

src/main/java/org/springframework/data/redis/core/ListOperations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public interface ListOperations<K, V> {
215215

216216
/**
217217
* Returns the index of the first occurrence of the specified value in the list at at {@code key}. <br />
218-
* Requires Redis 6.0.6
218+
* Requires Redis 6.0.6 or newer.
219219
*
220220
* @param key must not be {@literal null}.
221221
* @param value must not be {@literal null}.
@@ -227,7 +227,7 @@ public interface ListOperations<K, V> {
227227

228228
/**
229229
* Returns the index of the last occurrence of the specified value in the list at at {@code key}. <br />
230-
* Requires Redis 6.0.6
230+
* Requires Redis 6.0.6 or newer.
231231
*
232232
* @param key must not be {@literal null}.
233233
* @param value must not be {@literal null}.

src/main/java/org/springframework/data/redis/core/ReactiveListOperations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public interface ReactiveListOperations<K, V> {
198198

199199
/**
200200
* Returns the index of the first occurrence of the specified value in the list at at {@code key}. <br />
201-
* Requires Redis 6.0.6
201+
* Requires Redis 6.0.6 or newer.
202202
*
203203
* @param key must not be {@literal null}.
204204
* @param value must not be {@literal null}.
@@ -210,7 +210,7 @@ public interface ReactiveListOperations<K, V> {
210210

211211
/**
212212
* Returns the index of the last occurrence of the specified value in the list at at {@code key}. <br />
213-
* Requires Redis 6.0.6
213+
* Requires Redis 6.0.6 or newer.
214214
*
215215
* @param key must not be {@literal null}.
216216
* @param value must not be {@literal null}.

src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.redis.support.collections;
1717

1818
import static org.assertj.core.api.Assertions.*;
19+
import static org.assertj.core.api.Assumptions.*;
1920

2021
import java.util.ArrayList;
2122
import java.util.Arrays;
@@ -24,10 +25,10 @@
2425
import java.util.NoSuchElementException;
2526
import java.util.concurrent.TimeUnit;
2627

27-
import org.assertj.core.api.Assumptions;
2828
import org.junit.Before;
2929
import org.junit.Rule;
3030
import org.junit.Test;
31+
3132
import org.springframework.data.redis.ObjectFactory;
3233
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
3334
import org.springframework.data.redis.core.RedisTemplate;
@@ -168,7 +169,7 @@ public void addAllIndexCollectionMiddle() {
168169
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
169170
public void testIndexOfObject() {
170171

171-
Assumptions.assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
172+
assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
172173

173174
T t1 = getT();
174175
T t2 = getT();
@@ -249,10 +250,10 @@ public void testRange() {
249250
T t1 = getT();
250251
T t2 = getT();
251252

252-
assertThat(list.range(0, -1).isEmpty()).isTrue();
253+
assertThat(list.range(0, -1)).isEmpty();
253254
list.add(t1);
254255
list.add(t2);
255-
assertThat(list.range(0, -1).size()).isEqualTo(2);
256+
assertThat(list.range(0, -1)).hasSize(2);
256257
assertThat(list.range(0, 0).get(0)).isEqualTo(t1);
257258
assertThat(list.range(1, 1).get(0)).isEqualTo(t2);
258259
}
@@ -285,12 +286,12 @@ public void testTrim() {
285286
T t1 = getT();
286287
T t2 = getT();
287288

288-
assertThat(list.trim(0, 0).isEmpty()).isTrue();
289+
assertThat(list.trim(0, 0)).isEmpty();
289290
list.add(t1);
290291
list.add(t2);
291-
assertThat(list.size()).isEqualTo(2);
292-
assertThat(list.trim(0, 0).size()).isEqualTo(1);
293-
assertThat(list.size()).isEqualTo(1);
292+
assertThat(list).hasSize(2);
293+
assertThat(list.trim(0, 0)).hasSize(1);
294+
assertThat(list).hasSize(1);
294295
assertThat(list.get(0)).isEqualTo(t1);
295296
}
296297

@@ -300,12 +301,12 @@ public void testCappedCollection() throws Exception {
300301
RedisList<T> cappedList = new DefaultRedisList<T>(template.boundListOps(collection.getKey() + ":capped"), 1);
301302
T first = getT();
302303
cappedList.offer(first);
303-
assertThat(cappedList.size()).isEqualTo(1);
304+
assertThat(cappedList).hasSize(1);
304305
cappedList.add(getT());
305-
assertThat(cappedList.size()).isEqualTo(1);
306+
assertThat(cappedList).hasSize(1);
306307
T last = getT();
307308
cappedList.add(last);
308-
assertThat(cappedList.size()).isEqualTo(1);
309+
assertThat(cappedList).hasSize(1);
309310
assertThat(cappedList.get(0)).isEqualTo(first);
310311
}
311312

@@ -361,10 +362,8 @@ public void testDrainToCollectionWithMaxElements() {
361362
List<T> c = new ArrayList<>();
362363

363364
list.drainTo(c, 2);
364-
assertThat(list.size()).isEqualTo(1);
365-
assertThat(list).contains(t3);
366-
assertThat(c.size()).isEqualTo(2);
367-
assertThat(c).contains(t1, t2);
365+
assertThat(list).hasSize(1).contains(t3);
366+
assertThat(c).hasSize(2).contains(t1, t2);
368367
}
369368

370369
@SuppressWarnings("unchecked")
@@ -381,9 +380,8 @@ public void testDrainToCollection() {
381380
List<T> c = new ArrayList<>();
382381

383382
list.drainTo(c);
384-
assertThat(list.isEmpty()).isTrue();
385-
assertThat(c.size()).isEqualTo(3);
386-
assertThat(c).contains(t1, t2, t3);
383+
assertThat(list).isEmpty();
384+
assertThat(c).hasSize(3).contains(t1, t2, t3);
387385
}
388386

389387
@Test
@@ -426,7 +424,7 @@ public void testPeekLast() {
426424
list.add(t2);
427425

428426
assertThat(list.peekLast()).isEqualTo(t2);
429-
assertThat(list.size()).isEqualTo(2);
427+
assertThat(list).hasSize(2);
430428
}
431429

432430
@Test
@@ -444,8 +442,7 @@ public void testPollLast() {
444442

445443
T last = list.pollLast();
446444
assertThat(last).isEqualTo(t2);
447-
assertThat(list.size()).isEqualTo(1);
448-
assertThat(list).contains(t1);
445+
assertThat(list).hasSize(1).contains(t1);
449446
}
450447

451448
@Test
@@ -459,8 +456,7 @@ public void testPollLastTimeout() throws InterruptedException {
459456

460457
T last = list.pollLast(1, TimeUnit.MILLISECONDS);
461458
assertThat(last).isEqualTo(t2);
462-
assertThat(list.size()).isEqualTo(1);
463-
assertThat(list).contains(t1);
459+
assertThat(list).hasSize(1).contains(t1);
464460
}
465461

466462
@Test
@@ -500,6 +496,7 @@ public void testRemoveLast() {
500496

501497
@Test
502498
public void testRmoveLastOccurrence() {
499+
503500
T t1 = getT();
504501
T t2 = getT();
505502

@@ -509,11 +506,7 @@ public void testRmoveLastOccurrence() {
509506
list.add(t2);
510507

511508
list.removeLastOccurrence(t2);
512-
assertThat(list.size()).isEqualTo(3);
513-
Iterator<T> iterator = list.iterator();
514-
assertThat(iterator.next()).isEqualTo(t1);
515-
assertThat(iterator.next()).isEqualTo(t2);
516-
assertThat(iterator.next()).isEqualTo(t1);
509+
assertThat(list).hasSize(3).containsExactly(t1, t2, t1);
517510
}
518511

519512
@Test
@@ -535,7 +528,7 @@ public void testTakeLast() {
535528
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
536529
public void lastIndexOf() {
537530

538-
Assumptions.assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
531+
assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
539532

540533
T t1 = getT();
541534
T t2 = getT();

src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ public class RedisListTests extends AbstractRedisListTests<Object> {
3131
* @param factory
3232
* @param connFactory
3333
*/
34-
public RedisListTests(ObjectFactory<Object> factory, RedisTemplate template) {
34+
public RedisListTests(ObjectFactory<Object> factory, RedisTemplate<Object, Object> template) {
3535
super(factory, template);
3636
}
3737

3838
RedisStore copyStore(RedisStore store) {
39-
return new DefaultRedisList(store.getKey().toString(), store.getOperations());
39+
return new DefaultRedisList<>(store.getKey(), store.getOperations());
4040
}
4141

4242
AbstractRedisCollection<Object> createCollection() {
4343
String redisName = getClass().getName();
44-
return new DefaultRedisList(redisName, template);
44+
return new DefaultRedisList<>(redisName, template);
4545
}
4646
}

0 commit comments

Comments
 (0)