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 {
|
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||||
out.defaultWriteObject();
|
out.defaultWriteObject();
|
||||||
out.writeInt(size());
|
out.writeInt(size());
|
||||||
|
out.writeInt(buffer.length);
|
||||||
for (Iterator it = iterator(); it.hasNext();) {
|
for (Iterator it = iterator(); it.hasNext();) {
|
||||||
out.writeObject(it.next());
|
out.writeObject(it.next());
|
||||||
}
|
}
|
||||||
|
@ -130,7 +131,8 @@ public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, S
|
||||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||||
in.defaultReadObject();
|
in.defaultReadObject();
|
||||||
int size = in.readInt();
|
int size = in.readInt();
|
||||||
buffer = new Object[size + 1];
|
int length = in.readInt();
|
||||||
|
buffer = new Object[length];
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
buffer[i] = in.readObject();
|
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 {
|
public void testSerializeDeserializeThenCompare() throws Exception {
|
||||||
Object obj = makeObject();
|
Object obj = makeObject();
|
||||||
if (obj instanceof Serializable && isTestSerialization()) {
|
if (obj instanceof Serializable && isTestSerialization()) {
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
Object dest = serializeDeserialize(obj);
|
||||||
ObjectOutputStream out = new ObjectOutputStream(buffer);
|
|
||||||
out.writeObject(obj);
|
|
||||||
out.close();
|
|
||||||
|
|
||||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
|
|
||||||
Object dest = in.readObject();
|
|
||||||
in.close();
|
|
||||||
if (isEqualsCheckable()) {
|
if (isEqualsCheckable()) {
|
||||||
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
assertEquals("obj != deserialize(serialize(obj))", obj, dest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,6 +412,17 @@ public class TestUnboundedFifoBuffer extends AbstractTestCollection {
|
||||||
assertEquals(0, test.tail);
|
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() {
|
public String getCompatibilityVersion() {
|
||||||
return "3.1";
|
return "3.1";
|
||||||
|
|
Loading…
Reference in New Issue