1 10 11 package org.picocontainer.defaults; 12 13 import java.io.ByteArrayInputStream ; 14 import java.io.ByteArrayOutputStream ; 15 import java.io.IOException ; 16 import java.io.ObjectInputStream ; 17 import java.io.ObjectOutputStream ; 18 19 import org.picocontainer.MutablePicoContainer; 20 import org.picocontainer.PicoContainer; 21 import org.picocontainer.PicoException; 22 import org.picocontainer.PicoInitializationException; 23 import org.picocontainer.tck.AbstractPicoContainerTestCase; 24 25 29 public class DefaultPicoContainerTreeSerializationTestCase extends AbstractPicoContainerTestCase { 30 protected MutablePicoContainer createPicoContainer(PicoContainer parent) { 31 DefaultPicoContainer child = new DefaultPicoContainer(parent); 32 return child; 33 } 34 35 public void testContainerIsDeserializableWithParent() throws PicoException, PicoInitializationException, 36 IOException , ClassNotFoundException { 37 38 PicoContainer parent = createPicoContainer(null); 39 MutablePicoContainer child = createPicoContainer(parent); 40 41 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 42 ObjectOutputStream oos = new ObjectOutputStream (baos); 43 44 oos.writeObject(child); 45 46 child = null; 47 ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream (baos.toByteArray())); 48 child = (MutablePicoContainer) ois.readObject(); 49 assertNotNull(child.getParent()); 50 } 51 } 52 | Popular Tags |