Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 151   Methods: 5
NCLOC: 131   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MapCopyTest.java - 89.7% 100% 90.4%
coverage coverage
 1    package org.jboss.cache.util;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.util.stream.MarshalledValueInputStream;
 5    import org.jboss.util.stream.MarshalledValueOutputStream;
 6   
 7    import java.io.ByteArrayInputStream;
 8    import java.io.ByteArrayOutputStream;
 9    import java.io.ObjectInputStream;
 10    import java.io.ObjectOutputStream;
 11    import java.util.HashMap;
 12    import java.util.Map;
 13   
 14    public class MapCopyTest extends TestCase
 15    {
 16  1 public void testSerializable() throws Exception
 17    {
 18  1 HashMap hm = new HashMap();
 19  1 hm.put(null, null);
 20  1 hm.put("y", "z");
 21  1 MapCopy mc = new MapCopy(hm);
 22  1 assertEquals(hm, mc);
 23  1 ByteArrayOutputStream os = new ByteArrayOutputStream();
 24  1 ObjectOutputStream oos = new ObjectOutputStream(os);
 25  1 oos.writeObject(mc);
 26  1 ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
 27  1 ObjectInputStream ois = new ObjectInputStream(is);
 28  1 Object o = ois.readObject();
 29  1 assertEquals(hm, o);
 30    }
 31   
 32  1 public void testSerializableWithMarshalledValueStream() throws Exception
 33    {
 34  1 HashMap hm = new HashMap();
 35  1 hm.put(null, null);
 36  1 hm.put("y", "z");
 37  1 MapCopy mc = new MapCopy(hm);
 38  1 assertEquals(hm, mc);
 39  1 ByteArrayOutputStream os = new ByteArrayOutputStream();
 40  1 ObjectOutputStream oos = new MarshalledValueOutputStream(os);
 41  1 oos.writeObject(mc);
 42  1 ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
 43  1 ObjectInputStream ois = new MarshalledValueInputStream(is);
 44  1 Object o = ois.readObject();
 45  1 assertEquals(hm, o);
 46    }
 47   
 48  1 public void testNull()
 49    {
 50  1 HashMap hm = new HashMap();
 51  1 hm.put(null, null);
 52  1 MapCopy mc = new MapCopy(hm);
 53  1 assertEquals(hm, mc);
 54  1 assertEquals(hm.toString(), mc.toString());
 55   
 56  1 hm.put(null, "x");
 57  1 hm.put("y", null);
 58  1 mc = new MapCopy(hm);
 59  1 mc.toString();
 60  1 assertEquals(true, mc.containsKey("y"));
 61    }
 62   
 63  1 public void testAll()
 64    {
 65  1 HashMap hm = new HashMap();
 66  1 hm.put("a", "b");
 67  1 hm.put("b", "c");
 68  1 MapCopy mc = new MapCopy(hm);
 69  1 assertEquals(hm, mc);
 70  1 assertEquals(hm.size(), mc.size());
 71  1 try
 72    {
 73  1 mc.clear();
 74  0 fail("read only");
 75    }
 76    catch (UnsupportedOperationException e)
 77    {
 78    }
 79  1 HashMap bhm = new HashMap(hm);
 80  1 hm.put("b", "d");
 81  1 assertEquals(bhm, mc);
 82  1 Map.Entry me = (Map.Entry) mc.entrySet().iterator().next();
 83  1 try
 84    {
 85  1 me.setValue("arg");
 86  0 fail("read only");
 87    }
 88    catch (UnsupportedOperationException e)
 89    {
 90    }
 91    }
 92   
 93  1 public void testModifications()
 94    {
 95  1 Map hm = new HashMap();
 96  1 hm.put("a", "b");
 97  1 Map mc = new MapCopy(hm);
 98   
 99  1 try
 100    {
 101  1 mc.put("x", "y");
 102  0 fail("should fail");
 103    }
 104    catch (UnsupportedOperationException uoe)
 105    {
 106    // ok
 107    }
 108   
 109  1 try
 110    {
 111  1 mc.remove("a");
 112  0 fail("should fail");
 113    }
 114    catch (UnsupportedOperationException uoe)
 115    {
 116    // ok
 117    }
 118   
 119  1 try
 120    {
 121  1 mc.keySet().iterator().remove();
 122  0 fail("should fail");
 123    }
 124    catch (UnsupportedOperationException uoe)
 125    {
 126    // ok
 127    }
 128   
 129  1 try
 130    {
 131  1 mc.entrySet().iterator().remove();
 132  0 fail("should fail");
 133    }
 134    catch (UnsupportedOperationException uoe)
 135    {
 136    // ok
 137    }
 138   
 139  1 try
 140    {
 141  1 mc.values().iterator().remove();
 142  0 fail("should fail");
 143    }
 144    catch (UnsupportedOperationException uoe)
 145    {
 146    // ok
 147    }
 148   
 149   
 150    }
 151    }