Applying a unit test for COLLECTIONS-220. AbstractTestObject is refactored to provide a utility method that serializes and then deserializes. Dave Meikle's fix for said unit test is also applied.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@637495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b147d16e64
commit
7cf943172b
|
@ -115,6 +115,7 @@ public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, S
|
|||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeInt(size());
|
||||
out.writeInt(buffer.length);
|
||||
for (Iterator it = iterator(); it.hasNext();) {
|
||||
out.writeObject(it.next());
|
||||
}
|
||||
|
@ -130,7 +131,8 @@ public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, S
|
|||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
int size = in.readInt();
|
||||
buffer = new Object[size + 1];
|
||||
int length = in.readInt();
|
||||
buffer = new Object[length];
|
||||
for (int i = 0; i < size; i++) {
|
||||
buffer[i] = in.readObject();
|
||||
}
|
||||
|
|
|
@ -138,17 +138,23 @@ public abstract class AbstractTestObject extends BulkTest {
|
|||
}
|
||||
}
|
||||
|
||||
protected Object serializeDeserialize(Object obj) throws Exception {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(buffer);
|
||||
out.writeObject(obj);
|
||||
out.close();
|
||||
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||
Object dest = in.readObject();
|
||||
in.close();
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
public void testSerializeDeserializeThenCompare() throws Exception {
|
||||
Object obj = makeObject();
|
||||
if (obj instanceof Serializable && isTestSerialization()) {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(buffer);
|
||||
out.writeObject(obj);
|
||||
out.close();
|
||||
|
||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
||||
Object dest = in.readObject();
|
||||
in.close();
|
||||
Object dest = serializeDeserialize(obj);
|
||||
if (isEqualsCheckable()) {
|
||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||
}
|
||||
|
|
|
@ -412,6 +412,17 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection {
|
|||
assertEquals(0, test.tail);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testCollections220() throws Exception {
|
||||
UnboundedFifoBuffer buffer = new UnboundedFifoBuffer();
|
||||
|
||||
buffer = (UnboundedFifoBuffer) serializeDeserialize(buffer);
|
||||
|
||||
// test size() gets incremented
|
||||
buffer.add("Foo");
|
||||
assertEquals(1, buffer.size());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public String getCompatibilityVersion() {
|
||||
return "3.1";
|
||||
|
|
Loading…
Reference in New Issue