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 MarshallingInputStreamTest extends TestCase { 9 private ByteArrayOutputStream bytes; 10 private Marshaller marshaller; 11 private ObjectOutputStream 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 fail(); 29 return null; 30 } 31 32 public Object unmarshal(Object o) { 33 if (o instanceof MarshalledObject) { 34 return new MarshalObject(); 35 } else { 36 return o; 37 } 38 } 39 }; 40 41 out = new ObjectOutputStream(bytes); 42 } 43 44 public void testDontMarshalObject() throws IOException, ClassNotFoundException { 45 out.writeObject(new DontMarshalObject()); 46 47 MarshallingInputStream in = new MarshallingInputStream(new ByteArrayInputStream(bytes.toByteArray()), marshaller); 48 Object readObject = in.readObject(); 49 assertTrue(readObject instanceof DontMarshalObject); 50 } 51 52 public void testMarshalObject() throws IOException, ClassNotFoundException { 53 out.writeObject(new MarshalledObject()); 54 55 MarshallingInputStream in = new MarshallingInputStream(new ByteArrayInputStream(bytes.toByteArray()), marshaller); 56 Object readObject = in.readObject(); 57 assertTrue(readObject instanceof MarshalObject); 58 } 59 } 60 | Popular Tags |