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

View File

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

View File

@@ -146,7 +146,7 @@ public class ShardedJedisTest extends Assert {
expected.add("a".getBytes(Protocol.UTF8)); expected.add("a".getBytes(Protocol.UTF8));
expected.add("b".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("a".getBytes(Protocol.UTF8), results.get(0));
// assertArrayEquals("b".getBytes(Protocol.UTF8), results.get(1)); // 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[]>(); List<byte[]> bexpected = new ArrayList<byte[]>();
bexpected.add(bfoo); bexpected.add(bfoo);
bexpected.add(bfoobar); bexpected.add(bfoobar);
JedisTest.compareList(bexpected, bkeys); assertTrue(JedisTest.isListAreEquals(bexpected, bkeys));
// assertEquals(expected, keys); // assertEquals(expected, keys);
expected = new ArrayList<String>(); expected = new ArrayList<String>();