hvals now return a Collection, not a Set neither a List.
This commit is contained in:
@@ -49,6 +49,63 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
jedis.get("foo");
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static boolean isCollectionAreEquals(Collection expected, Collection result) {
|
||||
if(expected.size() != result.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Iterator expectedit = expected.iterator();
|
||||
while(expectedit.hasNext()) {
|
||||
final Object exp = expectedit.next();
|
||||
final Iterator responseit = result.iterator();
|
||||
boolean found = false;
|
||||
while(responseit.hasNext() && !found) {
|
||||
final Object resp = responseit.next();
|
||||
if(exp instanceof byte[] && resp instanceof byte[]) {
|
||||
final byte[] bexp = (byte[]) exp;
|
||||
final byte[] bresp = (byte[]) resp;
|
||||
if(Arrays.equals(bexp, bresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else if (exp instanceof Set && resp instanceof Set) {
|
||||
final Set subexp = (Set) exp;
|
||||
final Set subresp = (Set) resp;
|
||||
if(isSetAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else if (exp instanceof List && resp instanceof List) {
|
||||
final List subexp = (List) exp;
|
||||
final List subresp = (List) resp;
|
||||
if(isListAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else if (exp instanceof Collection && resp instanceof Collection) {
|
||||
final Collection subexp = (Collection) exp;
|
||||
final Collection subresp = (Collection) resp;
|
||||
if(isCollectionAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
if (null != exp) {
|
||||
if (exp.equals(resp)){
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
if(resp == null) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!found){
|
||||
fail("Result doesn't contain " + (null != exp ? exp.toString() : null));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static boolean isSetAreEquals(Set expected, Set result) {
|
||||
if(expected.size() != result.size()) {
|
||||
@@ -80,6 +137,12 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
if(isListAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else if (exp instanceof Collection && resp instanceof Collection) {
|
||||
final Collection subexp = (Collection) exp;
|
||||
final Collection subresp = (Collection) resp;
|
||||
if(isCollectionAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
if (null != exp) {
|
||||
if (exp.equals(resp)){
|
||||
@@ -131,6 +194,12 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
if(isListAreEquals(subexp, subresp)) {
|
||||
continue;
|
||||
}
|
||||
} else if (exp instanceof Collection && resp instanceof Collection) {
|
||||
final Collection subexp = (Collection) exp;
|
||||
final Collection subresp = (Collection) resp;
|
||||
if(isCollectionAreEquals(subexp, subresp)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (null != exp) {
|
||||
if (exp.equals(resp)){
|
||||
|
||||
@@ -249,11 +249,11 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
hash.put("car", "bar");
|
||||
jedis.hmset("foo", hash);
|
||||
|
||||
Set<String> vals = jedis.hvals("foo");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
Collection<String> vals = jedis.hvals("foo");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("car");
|
||||
expected.add("bar");
|
||||
assertTrue(JedisTest.isSetAreEquals(expected, vals));
|
||||
assertTrue(JedisTest.isCollectionAreEquals(expected, vals));
|
||||
|
||||
//Binary
|
||||
Map<byte[], byte[]> bhash = new LinkedHashMap<byte[], byte[]>();
|
||||
@@ -261,11 +261,11 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
bhash.put(bcar, bbar);
|
||||
jedis.hmset(bfoo, bhash);
|
||||
|
||||
Set<byte[]> bvals = jedis.hvals(bfoo);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
Collection<byte[]> bvals = jedis.hvals(bfoo);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bcar);
|
||||
bexpected.add(bbar);
|
||||
assertTrue(JedisTest.isSetAreEquals(bexpected, bvals));
|
||||
assertTrue(JedisTest.isCollectionAreEquals(bexpected, bvals));
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user