DATAREDIS-1196 - Polishing.
Tweak Redis 6.0.6 requirement wording. Join assertions where possible and use more concise assertions. Original pull request: #563.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.redis.support.collections;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assumptions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -24,10 +25,10 @@ import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.api.Assumptions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.redis.ObjectFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -168,7 +169,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
|
||||
public void testIndexOfObject() {
|
||||
|
||||
Assumptions.assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
|
||||
assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
|
||||
|
||||
T t1 = getT();
|
||||
T t2 = getT();
|
||||
@@ -249,10 +250,10 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
T t1 = getT();
|
||||
T t2 = getT();
|
||||
|
||||
assertThat(list.range(0, -1).isEmpty()).isTrue();
|
||||
assertThat(list.range(0, -1)).isEmpty();
|
||||
list.add(t1);
|
||||
list.add(t2);
|
||||
assertThat(list.range(0, -1).size()).isEqualTo(2);
|
||||
assertThat(list.range(0, -1)).hasSize(2);
|
||||
assertThat(list.range(0, 0).get(0)).isEqualTo(t1);
|
||||
assertThat(list.range(1, 1).get(0)).isEqualTo(t2);
|
||||
}
|
||||
@@ -285,12 +286,12 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
T t1 = getT();
|
||||
T t2 = getT();
|
||||
|
||||
assertThat(list.trim(0, 0).isEmpty()).isTrue();
|
||||
assertThat(list.trim(0, 0)).isEmpty();
|
||||
list.add(t1);
|
||||
list.add(t2);
|
||||
assertThat(list.size()).isEqualTo(2);
|
||||
assertThat(list.trim(0, 0).size()).isEqualTo(1);
|
||||
assertThat(list.size()).isEqualTo(1);
|
||||
assertThat(list).hasSize(2);
|
||||
assertThat(list.trim(0, 0)).hasSize(1);
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list.get(0)).isEqualTo(t1);
|
||||
}
|
||||
|
||||
@@ -300,12 +301,12 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
RedisList<T> cappedList = new DefaultRedisList<T>(template.boundListOps(collection.getKey() + ":capped"), 1);
|
||||
T first = getT();
|
||||
cappedList.offer(first);
|
||||
assertThat(cappedList.size()).isEqualTo(1);
|
||||
assertThat(cappedList).hasSize(1);
|
||||
cappedList.add(getT());
|
||||
assertThat(cappedList.size()).isEqualTo(1);
|
||||
assertThat(cappedList).hasSize(1);
|
||||
T last = getT();
|
||||
cappedList.add(last);
|
||||
assertThat(cappedList.size()).isEqualTo(1);
|
||||
assertThat(cappedList).hasSize(1);
|
||||
assertThat(cappedList.get(0)).isEqualTo(first);
|
||||
}
|
||||
|
||||
@@ -361,10 +362,8 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
List<T> c = new ArrayList<>();
|
||||
|
||||
list.drainTo(c, 2);
|
||||
assertThat(list.size()).isEqualTo(1);
|
||||
assertThat(list).contains(t3);
|
||||
assertThat(c.size()).isEqualTo(2);
|
||||
assertThat(c).contains(t1, t2);
|
||||
assertThat(list).hasSize(1).contains(t3);
|
||||
assertThat(c).hasSize(2).contains(t1, t2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -381,9 +380,8 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
List<T> c = new ArrayList<>();
|
||||
|
||||
list.drainTo(c);
|
||||
assertThat(list.isEmpty()).isTrue();
|
||||
assertThat(c.size()).isEqualTo(3);
|
||||
assertThat(c).contains(t1, t2, t3);
|
||||
assertThat(list).isEmpty();
|
||||
assertThat(c).hasSize(3).contains(t1, t2, t3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -426,7 +424,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t2);
|
||||
|
||||
assertThat(list.peekLast()).isEqualTo(t2);
|
||||
assertThat(list.size()).isEqualTo(2);
|
||||
assertThat(list).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -444,8 +442,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
|
||||
T last = list.pollLast();
|
||||
assertThat(last).isEqualTo(t2);
|
||||
assertThat(list.size()).isEqualTo(1);
|
||||
assertThat(list).contains(t1);
|
||||
assertThat(list).hasSize(1).contains(t1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -459,8 +456,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
|
||||
T last = list.pollLast(1, TimeUnit.MILLISECONDS);
|
||||
assertThat(last).isEqualTo(t2);
|
||||
assertThat(list.size()).isEqualTo(1);
|
||||
assertThat(list).contains(t1);
|
||||
assertThat(list).hasSize(1).contains(t1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -500,6 +496,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
|
||||
@Test
|
||||
public void testRmoveLastOccurrence() {
|
||||
|
||||
T t1 = getT();
|
||||
T t2 = getT();
|
||||
|
||||
@@ -509,11 +506,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
list.add(t2);
|
||||
|
||||
list.removeLastOccurrence(t2);
|
||||
assertThat(list.size()).isEqualTo(3);
|
||||
Iterator<T> iterator = list.iterator();
|
||||
assertThat(iterator.next()).isEqualTo(t1);
|
||||
assertThat(iterator.next()).isEqualTo(t2);
|
||||
assertThat(iterator.next()).isEqualTo(t1);
|
||||
assertThat(list).hasSize(3).containsExactly(t1, t2, t1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -535,7 +528,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
|
||||
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
|
||||
public void lastIndexOf() {
|
||||
|
||||
Assumptions.assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
|
||||
assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
|
||||
|
||||
T t1 = getT();
|
||||
T t2 = getT();
|
||||
|
||||
@@ -31,16 +31,16 @@ public class RedisListTests extends AbstractRedisListTests<Object> {
|
||||
* @param factory
|
||||
* @param connFactory
|
||||
*/
|
||||
public RedisListTests(ObjectFactory<Object> factory, RedisTemplate template) {
|
||||
public RedisListTests(ObjectFactory<Object> factory, RedisTemplate<Object, Object> template) {
|
||||
super(factory, template);
|
||||
}
|
||||
|
||||
RedisStore copyStore(RedisStore store) {
|
||||
return new DefaultRedisList(store.getKey().toString(), store.getOperations());
|
||||
return new DefaultRedisList<>(store.getKey(), store.getOperations());
|
||||
}
|
||||
|
||||
AbstractRedisCollection<Object> createCollection() {
|
||||
String redisName = getClass().getName();
|
||||
return new DefaultRedisList(redisName, template);
|
||||
return new DefaultRedisList<>(redisName, template);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user