RedisList extends RedisCollection<T> implements List<T> { @Override public boolean add(T e) { Objects.requireNonNull(e); int index = size(); if (index == 0) { if(isString) { jedis.lpush(keyWithNameSpace, e.toString()); } else { jedis.lpush(keyWithNameSpace, JSONB.toJson(e)); } } else { String previewValue = jedis.lindex(keyWithNameSpace, index - 1); if(isString) { jedis.linsert(keyWithNameSpace, ListPosition.AFTER, previewValue, e.toString()); }else { jedis.linsert(keyWithNameSpace, ListPosition.AFTER, previewValue, JSONB.toJson(e)); } } return true; } RedisList(Jedis jedis, Class<T> clazz, String keyWithNameSpace); @Override int size(); @Override boolean isEmpty(); @Override ListIterator<T> listIterator(); @Override ListIterator<T> listIterator(int index); @Override Iterator<T> iterator(); @Override boolean add(T e); @Override boolean addAll(int index, Collection<? extends T> elements); @Override void clear(); @Override T get(int index); @Override T set(int index, T element); @Override void add(int index, T element); @Override T remove(int index); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @Override List<T> subList(int fromIndex, int toIndex);  }
@Test public void shouldReturnContains() { fruits.add(orange); fruits.add(banana); fruits.add(waterMelon); assertTrue(fruits.contains(banana)); assertFalse(fruits.contains(melon)); assertTrue(fruits.containsAll(Arrays.asList(banana, orange))); assertFalse(fruits.containsAll(Arrays.asList(banana, melon))); }