RedissonMap new tests added

pull/6/head
Nikita 11 years ago
parent dc9d61699d
commit 97978e3222

@ -31,6 +31,31 @@ public class RedissonMapTest {
return "key: " + key;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SimpleKey other = (SimpleKey) obj;
if (key == null) {
if (other.key != null)
return false;
} else if (!key.equals(other.key))
return false;
return true;
}
}
public static class SimpleValue {
@ -57,6 +82,104 @@ public class RedissonMapTest {
return "value: " + value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SimpleValue other = (SimpleValue) obj;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
}
@Test
public void testSimpleTypes() {
Redisson redisson = Redisson.create();
Map<Integer, String> map = redisson.getMap("simple12");
map.put(1, "12");
map.put(2, "33");
map.put(3, "43");
String val = map.get(2);
Assert.assertEquals("33", val);
clear(map);
}
@Test
public void testRemove() {
Redisson redisson = Redisson.create();
Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"));
map.put(new SimpleKey("33"), new SimpleValue("44"));
map.put(new SimpleKey("5"), new SimpleValue("6"));
map.remove(new SimpleKey("33"));
map.remove(new SimpleKey("5"));
Assert.assertEquals(1, map.size());
clear(map);
}
@Test
public void testKeySet() {
Redisson redisson = Redisson.create();
Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"));
map.put(new SimpleKey("33"), new SimpleValue("44"));
map.put(new SimpleKey("5"), new SimpleValue("6"));
Assert.assertTrue(map.keySet().contains(new SimpleKey("33")));
Assert.assertFalse(map.keySet().contains(new SimpleKey("44")));
clear(map);
}
@Test
public void testContainsValue() {
Redisson redisson = Redisson.create();
Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"));
map.put(new SimpleKey("33"), new SimpleValue("44"));
map.put(new SimpleKey("5"), new SimpleValue("6"));
Assert.assertTrue(map.containsValue(new SimpleValue("2")));
Assert.assertFalse(map.containsValue(new SimpleValue("441")));
Assert.assertFalse(map.containsValue(new SimpleKey("5")));
clear(map);
}
@Test
public void testContainsKey() {
Redisson redisson = Redisson.create();
Map<SimpleKey, SimpleValue> map = redisson.getMap("simple");
map.put(new SimpleKey("1"), new SimpleValue("2"));
map.put(new SimpleKey("33"), new SimpleValue("44"));
map.put(new SimpleKey("5"), new SimpleValue("6"));
Assert.assertTrue(map.containsKey(new SimpleKey("33")));
Assert.assertFalse(map.containsKey(new SimpleKey("34")));
clear(map);
}
@Test
@ -120,6 +243,9 @@ public class RedissonMapTest {
map.put(new SimpleKey("51"), new SimpleValue("6"));
Assert.assertEquals(4, map.size());
map.remove(new SimpleKey("3"));
Assert.assertEquals(3, map.size());
clear(map);
}

Loading…
Cancel
Save