public void testSerialization() throws Exception {
  LinkedBlockingQueue q=populatedQueue(SIZE);
  ByteArrayOutputStream bout=new ByteArrayOutputStream(10000);
  ObjectOutputStream out=new ObjectOutputStream(new BufferedOutputStream(bout));
  out.writeObject(q);
  out.close();
  ByteArrayInputStream bin=new ByteArrayInputStream(bout.toByteArray());
  ObjectInputStream in=new ObjectInputStream(new BufferedInputStream(bin));
  LinkedBlockingQueue r=(LinkedBlockingQueue)in.readObject();
  assertEquals(q.size(),r.size());
  while (!q.isEmpty())   assertEquals(q.remove(),r.remove());
}

public void testSerialization ( ) throws Exception { LinkedBlockingQueue q = populatedQueue ( SIZE ) ; ByteArrayOutputStream bout = new ByteArrayOutputStream ( 10000 ) ; ObjectOutputStream out = new ObjectOutputStream ( new BufferedOutputStream ( bout ) ) ; out . writeObject ( q ) ; out . close ( ) ; ByteArrayInputStream bin = new ByteArrayInputStream ( bout . toByteArray ( ) ) ; ObjectInputStream in = new ObjectInputStream ( new BufferedInputStream ( bin ) ) ; LinkedBlockingQueue r = ( LinkedBlockingQueue ) in . readObject ( ) ; assertEquals ( q . size ( ) , r . size ( ) ) ; while ( ! q . isEmpty ( ) ) assertEquals ( q . remove ( ) , r . remove ( ) ) ; }
a deserialized serialized queue has same elements in same order
