1 package com.tirsen.nanning.samples.rmi; 2 3 import junit.framework.TestCase; 4 import com.tirsen.nanning.samples.prevayler.Marshaller; 5 6 import java.io.*; 7 8 public class MarshallingOutputStreamTest extends TestCase { 9 private ByteArrayOutputStream bytes; 10 private Marshaller marshaller; 11 private MarshallingOutputStream out; 12 13 public static class DontMarshalObject implements Serializable { 14 } 15 16 public static class MarshalObject implements Serializable { 17 } 18 19 public static class MarshalledObject implements Serializable { 20 } 21 22 protected void setUp() throws Exception { 23 super.setUp(); 24 25 bytes = new ByteArrayOutputStream(); 26 marshaller = new Marshaller() { 27 public Object marshal(Object o) { 28 if (o instanceof MarshalObject) { 29 return new MarshalledObject(); 30 } else { 31 return o; 32 } 33 } 34 35 public Object unmarshal(Object o) { 36 fail(); 37 return null; 38 } 39 }; 40 41 out = new MarshallingOutputStream(bytes, marshaller); 42 } 43 44 public void testWriteDontMarshalObject() throws IOException, ClassNotFoundException { 45 out.writeObject(new DontMarshalObject()); 46 out.flush(); 47 48 Object readObject = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())).readObject(); 49 assertTrue(readObject instanceof DontMarshalObject); 50 } 51 52 public void testWriteMarshalObject() throws IOException, ClassNotFoundException { 53 out.writeObject(new MarshalObject()); 54 out.flush(); 55 56 Object readObject = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())).readObject(); 57 assertTrue(readObject instanceof MarshalledObject); 58 } 59 } 60 | Popular Tags |