From 88c2fb9f0352d6bce0ecd38f232cd373948fedf0 Mon Sep 17 00:00:00 2001
From: Nikita <abracham.mitchell@gmail.com>
Date: Thu, 2 Jan 2014 21:53:21 +0400
Subject: [PATCH] RedissonList.indexOf test added

---
 src/main/java/org/redisson/RedissonList.java  |   2 +-
 .../java/org/redisson/RedissonListTest.java   | 111 ++++++++++++++++++
 2 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/redisson/RedissonList.java b/src/main/java/org/redisson/RedissonList.java
index 62ab8fff2..a52fb7ef5 100644
--- a/src/main/java/org/redisson/RedissonList.java
+++ b/src/main/java/org/redisson/RedissonList.java
@@ -177,7 +177,7 @@ public class RedissonList<V> implements List<V> {
         int batchSize = 50;
         int to = Math.max(size()/batchSize, 1);
         for (int i = 0; i < to; i++) {
-            List<Object> range = connection.lrange(name, i*batchSize, i*batchSize + batchSize);
+            List<Object> range = connection.lrange(name, i*batchSize, i*batchSize + batchSize - 1);
             int index = range.indexOf(o);
             if (index != -1) {
                 return index + i*batchSize;
diff --git a/src/test/java/org/redisson/RedissonListTest.java b/src/test/java/org/redisson/RedissonListTest.java
index ed38ac92f..c91647987 100644
--- a/src/test/java/org/redisson/RedissonListTest.java
+++ b/src/test/java/org/redisson/RedissonListTest.java
@@ -11,6 +11,117 @@ import org.junit.Test;
 
 public class RedissonListTest {
 
+    @Test
+    public void testIndexOf() {
+        Redisson redisson = Redisson.create();
+        List<Integer> list = redisson.getList("list");
+        for (int i = 1; i < 200; i++) {
+            list.add(i);
+        }
+
+        Assert.assertTrue(55 == list.indexOf(56));
+        Assert.assertTrue(99 == list.indexOf(100));
+        Assert.assertTrue(-1 == list.indexOf(200));
+        Assert.assertTrue(-1 == list.indexOf(0));
+
+        clear(list);
+    }
+
+
+    @Test
+    public void testRemove() {
+        Redisson redisson = Redisson.create();
+        List<Integer> list = redisson.getList("list");
+        list.add(1);
+        list.add(2);
+        list.add(3);
+        list.add(4);
+        list.add(5);
+
+        Integer val = list.remove(0);
+        Assert.assertTrue(1 == val);
+
+        Assert.assertThat(list, Matchers.contains(2, 3, 4, 5));
+
+        clear(list);
+    }
+
+    @Test
+    public void testSet() {
+        Redisson redisson = Redisson.create();
+        List<Integer> list = redisson.getList("list");
+        list.add(1);
+        list.add(2);
+        list.add(3);
+        list.add(4);
+        list.add(5);
+
+        list.set(4, 6);
+
+        Assert.assertThat(list, Matchers.contains(1, 2, 3, 4, 6));
+        clear(list);
+    }
+
+    @Test(expected = IndexOutOfBoundsException.class)
+    public void testSetFail() {
+        Redisson redisson = Redisson.create();
+        List<Integer> list = redisson.getList("list");
+        list.add(1);
+        list.add(2);
+        list.add(3);
+        list.add(4);
+        list.add(5);
+
+        try {
+            list.set(5, 6);
+        } finally {
+            clear(list);
+        }
+    }
+
+    @Test
+    public void testSetList() {
+        List<Integer> list = new LinkedList<Integer>();
+        list.add(1);
+        list.add(2);
+        list.add(3);
+        list.add(4);
+        list.add(5);
+
+        list.set(4, 6);
+
+        Assert.assertThat(list, Matchers.contains(1, 2, 3, 4, 6));
+
+        clear(list);
+    }
+
+
+    @Test
+    public void testRemoveAll() {
+        Redisson redisson = Redisson.create();
+        List<Integer> list = redisson.getList("list");
+        list.add(1);
+        list.add(2);
+        list.add(3);
+        list.add(4);
+        list.add(5);
+
+        list.removeAll(Arrays.asList(3, 2, 10, 6));
+
+        Assert.assertThat(list, Matchers.contains(1, 4, 5));
+
+        list.removeAll(Arrays.asList(4));
+
+        Assert.assertThat(list, Matchers.contains(1, 5));
+
+        list.removeAll(Arrays.asList(1, 5, 1, 5));
+
+        Assert.assertTrue(list.isEmpty());
+
+        clear(list);
+    }
+
+
     @Test
     public void testAddAllIndex() {
         Redisson redisson = Redisson.create();