Fix some more U tests ...

This commit is contained in:
Yaourt
2010-11-05 09:53:37 +01:00
parent dab21609e6
commit f8afa09aa5
4 changed files with 26 additions and 18 deletions

View File

@@ -5,6 +5,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.tree.ExpandVetoException;
import org.junit.Test;
import org.junit.Assert;
import redis.clients.jedis.Jedis;
@@ -45,8 +47,10 @@ public class JedisTest extends JedisCommandTestBase {
}
@SuppressWarnings("rawtypes")
public static void compareList(List expected, List result) {
assertEquals(expected.size(), result.size());
public static boolean isListAreEquals(List expected, List result) {
if(expected.size() != result.size()) {
return false;
}
final Iterator expectedit = expected.iterator();
while(expectedit.hasNext()) {
@@ -55,28 +59,34 @@ public class JedisTest extends JedisCommandTestBase {
boolean found = false;
while(responseit.hasNext() && !found) {
final Object resp = responseit.next();
if(exp instanceof byte[]) {
if(exp instanceof byte[] && resp instanceof byte[]) {
final byte[] bexp = (byte[]) exp;
final byte[] bresp = (byte[]) resp;
if(arraysAreEquals(bexp, bresp)) {
if(isArraysAreEquals(bexp, bresp)) {
found = true;
}
// Assert.assertArrayEquals(bexp, bresp);
} else if (exp instanceof List) {
} else if (exp instanceof List && resp instanceof List) {
final List subexp = (List) exp;
final List subresp = (List) resp;
compareList(subexp, subresp);
if(isListAreEquals(subexp, subresp)) {
found = true;
}
} else {
assertEquals(exp, resp);
if (exp.equals(resp)){
found = true;
}
}
}
if(!found){
fail("Result doesn't contain " + exp.toString());
}
}
return true;
}
public static boolean arraysAreEquals(final byte[] expected, final byte[] result) {
public static boolean isArraysAreEquals(final byte[] expected, final byte[] result) {
if(expected.length != result.length) {
return false;
}

View File

@@ -45,8 +45,8 @@ public class ProtocolTest extends Assert {
public void bulkReply() {
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());
Protocol protocol = new Protocol();
String response = (String) protocol.read(new RedisInputStream(is));
assertEquals("foobar", response);
byte[] response = (byte[]) protocol.read(new RedisInputStream(is));
assertArrayEquals("foobar".getBytes(Protocol.UTF8), response);
}
@Test
@@ -54,8 +54,8 @@ public class ProtocolTest extends Assert {
FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream(
"$30\r\n012345678901234567890123456789\r\n".getBytes());
Protocol protocol = new Protocol();
String response = (String) protocol.read(new RedisInputStream(fis));
assertEquals("012345678901234567890123456789", response);
byte[] response = (byte[]) protocol.read(new RedisInputStream(fis));
assertArrayEquals("012345678901234567890123456789".getBytes(Protocol.UTF8), response);
}
@Test
@@ -96,8 +96,7 @@ public class ProtocolTest extends Assert {
expected.add("Hello".getBytes(Protocol.UTF8));
expected.add("World".getBytes(Protocol.UTF8));
assertEquals(expected.size(), response.size());
JedisTest.compareList(expected, response);
assertTrue(JedisTest.isListAreEquals(expected, response));
// final Iterator<byte[]> expectedit = expected.iterator();
// final Iterator<byte[]> responseit = response.iterator();
// while(expectedit.hasNext()) {
@@ -120,8 +119,7 @@ public class ProtocolTest extends Assert {
sub.add("bar".getBytes(Protocol.UTF8));
expected2.add(sub);
assertEquals(expected2.size(), response2.size());
JedisTest.compareList(expected2, response2);
assertTrue(JedisTest.isListAreEquals(expected2, response2));
// final Iterator<Object> expectedit2 = expected2.iterator();
// final Iterator<Object> responseit2 = response2.iterator();
// while(expectedit2.hasNext()) {

View File

@@ -146,7 +146,7 @@ public class ShardedJedisTest extends Assert {
expected.add("a".getBytes(Protocol.UTF8));
expected.add("b".getBytes(Protocol.UTF8));
JedisTest.compareList(expected, results);
assertTrue(JedisTest.isListAreEquals(expected, results));
// assertArrayEquals("a".getBytes(Protocol.UTF8), results.get(0));
// assertArrayEquals("b".getBytes(Protocol.UTF8), results.get(1));
}

View File

@@ -140,7 +140,7 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
List<byte[]> bexpected = new ArrayList<byte[]>();
bexpected.add(bfoo);
bexpected.add(bfoobar);
JedisTest.compareList(bexpected, bkeys);
assertTrue(JedisTest.isListAreEquals(bexpected, bkeys));
// assertEquals(expected, keys);
expected = new ArrayList<String>();