Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 84   Methods: 4
NCLOC: 68   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MethodIdPreservationTest.java - 100% 100% 100%
coverage
 1    package org.jboss.cache.marshall;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.cache.Fqn;
 5   
 6    import java.io.ByteArrayInputStream;
 7    import java.io.ByteArrayOutputStream;
 8    import java.io.ObjectInputStream;
 9    import java.io.ObjectOutputStream;
 10    import java.util.ArrayList;
 11    import java.util.List;
 12   
 13    /**
 14    * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
 15    * @since 2.0.0
 16    */
 17    public class MethodIdPreservationTest extends TestCase
 18    {
 19    private Marshaller m = new CacheMarshaller200(null, false, false);
 20    private ObjectOutputStream stream;
 21    private ByteArrayOutputStream byteStream;
 22    private MethodCall call1;
 23    private MethodCall call2;
 24    private List<MethodCall> list = new ArrayList<MethodCall>(2);
 25    private MethodCall prepareCall;
 26   
 27  3 protected void setUp() throws Exception
 28    {
 29  3 byteStream = new ByteArrayOutputStream();
 30  3 stream = new ObjectOutputStream(byteStream);
 31  3 call1 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.ROOT, null, null, true);
 32  3 call2 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.ROOT, null, null, true);
 33  3 list.clear();
 34  3 list.add(call1);
 35  3 list.add(call2);
 36  3 prepareCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, null, list, null, true);
 37    }
 38   
 39  1 public void testSingleMethodCall() throws Exception
 40    {
 41  1 m.objectToObjectStream(call1, stream);
 42  1 stream.close();
 43  1 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
 44  1 Object result = m.objectFromObjectStream(in);
 45  1 assertEquals(call1.getClass(), result.getClass());
 46   
 47  1 MethodCall resultMethod = (MethodCall) result;
 48  1 assertEquals(call1.getMethodId(), resultMethod.getMethodId());
 49    }
 50   
 51  1 public void testListOfMethodCalls() throws Exception
 52    {
 53  1 m.objectToObjectStream(list, stream);
 54  1 stream.close();
 55  1 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
 56  1 Object result = m.objectFromObjectStream(in);
 57  1 assertEquals(list.getClass(), result.getClass());
 58  1 assertEquals(list.size(), ((List) result).size());
 59  1 MethodCall result1 = (MethodCall) ((List) result).get(0);
 60  1 MethodCall result2 = (MethodCall) ((List) result).get(1);
 61   
 62  1 assertEquals(call1.getMethodId(), result1.getMethodId());
 63  1 assertEquals(call2.getMethodId(), result2.getMethodId());
 64    }
 65   
 66  1 public void testMethodCallsInPrepare() throws Exception
 67    {
 68  1 m.objectToObjectStream(prepareCall, stream);
 69  1 stream.close();
 70  1 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
 71  1 Object result = m.objectFromObjectStream(in);
 72   
 73  1 assertEquals(prepareCall.getClass(), result.getClass());
 74  1 MethodCall prepareCallRes = (MethodCall) result;
 75  1 List listResult = (List) prepareCallRes.getArgs()[1];
 76   
 77  1 assertEquals(list.size(), listResult.size());
 78  1 MethodCall result1 = (MethodCall) listResult.get(0);
 79  1 MethodCall result2 = (MethodCall) listResult.get(1);
 80   
 81  1 assertEquals(call1.getMethodId(), result1.getMethodId());
 82  1 assertEquals(call2.getMethodId(), result2.getMethodId());
 83    }
 84    }