mirror of
https://github.com/apache/struts.git
synced 2026-08-11 09:36:57 +00:00
fixes broken tests due to WW-4544 / #48
This commit is contained in:
@@ -77,7 +77,7 @@ public class ContainUtil {
|
||||
}
|
||||
} if (obj1 instanceof Iterable) {
|
||||
for (Object value : ((Iterable) obj1)) {
|
||||
if (obj2.equals(value) || obj2.toString().equals(value.toString())) {
|
||||
if (obj2.equals(value) || (value != null && obj2.toString().equals(value.toString()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class ContainUtil {
|
||||
for (int i = 0; i < Array.getLength(obj1); i++) {
|
||||
Object value = Array.get(obj1, i);
|
||||
|
||||
if (obj2.equals(value) || obj2.toString().equals(value.toString())) {
|
||||
if (obj2.equals(value) || (value != null && obj2.toString().equals(value.toString()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ public class ContainUtilTest extends TestCase {
|
||||
assertTrue(ContainUtil.contains(new String[] {"a", null, "b"}, "b"));
|
||||
}
|
||||
|
||||
public void testArayContainsNull()throws Exception {
|
||||
// null gives always false
|
||||
assertFalse(ContainUtil.contains(new String[] {"a", null, "b"}, null));
|
||||
}
|
||||
|
||||
public void testSimpleList() throws Exception {
|
||||
List<String> l = new ArrayList<String>();
|
||||
l.add("one");
|
||||
@@ -96,13 +101,28 @@ public class ContainUtilTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testIterableObject() throws Exception {
|
||||
MyIterableObject i = new MyIterableObject("one", "two");
|
||||
MyIterableObject i = new MyIterableObject("one", "two");
|
||||
|
||||
assertFalse(ContainUtil.contains(i, "thre"));
|
||||
assertTrue(ContainUtil.contains(i, "one"));
|
||||
assertTrue(ContainUtil.contains(i, "two"));
|
||||
}
|
||||
|
||||
|
||||
public void testNullInIterableObject() throws Exception {
|
||||
MyIterableObject i = new MyIterableObject("one", null, "two");
|
||||
|
||||
assertFalse(ContainUtil.contains(i, "thre"));
|
||||
assertTrue(ContainUtil.contains(i, "one"));
|
||||
assertTrue(ContainUtil.contains(i, "two"));
|
||||
}
|
||||
|
||||
public void testIterableObjectContainsNull() throws Exception {
|
||||
MyIterableObject i = new MyIterableObject("one", null, "two");
|
||||
|
||||
// null gives always false
|
||||
assertFalse(ContainUtil.contains(i, null));
|
||||
}
|
||||
|
||||
public static class MyIterableObject implements Iterable<String> {
|
||||
private List<String> values;
|
||||
|
||||
@@ -126,7 +146,11 @@ public class ContainUtilTest extends TestCase {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((age == null) ? 0 : age.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user