RedissonSet tests added

pull/6/head
Nikita 11 years ago
parent 66ff10071e
commit cf50468200

@ -50,6 +50,7 @@ public class RedissonSet<V> implements Set<V> {
@Override
public Iterator<V> iterator() {
// TODO use SSCAN in case of usage Redis 2.8
return (Iterator<V>) connection.smembers(name).iterator();
}

@ -0,0 +1,16 @@
package org.redisson;
import java.util.Collection;
import org.junit.Assert;
public abstract class BaseRedissonTest {
protected void clear(Collection<?> collection, Redisson redisson) {
collection.clear();
Assert.assertEquals(0, collection.size());
redisson.shutdown();
}
}

@ -12,7 +12,7 @@ import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
public class RedissonListTest {
public class RedissonListTest extends BaseRedissonTest {
@Test(expected = IllegalStateException.class)
public void testListIteratorSetListFail() {
@ -684,6 +684,21 @@ public class RedissonListTest {
clear(list, redisson);
}
@Test
public void testDuplicates() {
Redisson redisson = Redisson.create();
List<TestObject> list = redisson.getList("list");
list.add(new TestObject("1", "2"));
list.add(new TestObject("1", "2"));
list.add(new TestObject("2", "3"));
list.add(new TestObject("3", "4"));
list.add(new TestObject("5", "6"));
Assert.assertEquals(5, list.size());
clear(list, redisson);
}
@Test
public void testSize() {
@ -707,12 +722,4 @@ public class RedissonListTest {
clear(list, redisson);
}
private void clear(Collection<?> list, Redisson redisson) {
list.clear();
Assert.assertEquals(0, list.size());
redisson.shutdown();
}
}

@ -0,0 +1,45 @@
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
public class RedissonSetTest extends BaseRedissonTest {
@Test
public void testDuplicates() {
Redisson redisson = Redisson.create();
Set<TestObject> set = redisson.getSet("list");
set.add(new TestObject("1", "2"));
set.add(new TestObject("1", "2"));
set.add(new TestObject("2", "3"));
set.add(new TestObject("3", "4"));
set.add(new TestObject("5", "6"));
Assert.assertEquals(4, set.size());
clear(set, redisson);
}
@Test
public void testSize() {
Redisson redisson = Redisson.create();
Set<Integer> set = redisson.getSet("set");
set.add(1);
set.add(2);
set.add(3);
set.add(3);
set.add(4);
set.add(5);
set.add(5);
Assert.assertEquals(5, set.size());
clear(set, redisson);
}
}

@ -0,0 +1,25 @@
package org.redisson;
public class TestObject {
private String name;
private String value;
public TestObject() {
}
public TestObject(String name, String value) {
super();
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
}
Loading…
Cancel
Save