public void testSerialization() throws Exception { IdentityHashBag bag2 = (IdentityHashBag) TestTools.serialize(this.bag); assertTrue("same object?", this.bag != bag2); assertEquals(11, bag2.size()); assertEquals(CollectionTools.bag(this.bag.iterator()), CollectionTools.bag(bag2.iterator())); // look for similar elements assertTrue(CollectionTools.bag(bag2.iterator()).contains(null)); assertTrue(CollectionTools.bag(bag2.iterator()).contains("one")); assertTrue(CollectionTools.bag(bag2.iterator()).contains("two")); assertTrue(CollectionTools.bag(bag2.iterator()).contains("three")); assertTrue(CollectionTools.bag(bag2.iterator()).contains("four")); int nullCount = 0, oneCount = 0, twoCount = 0, threeCount = 0, fourCount = 0; for (Iterator stream = bag2.iterator(); stream.hasNext(); ) { String next = (String) stream.next(); if (next == null) nullCount++; else if (next.equals("one")) oneCount++; else if (next.equals("two")) twoCount++; else if (next.equals("three")) threeCount++; else if (next.equals("four")) fourCount++; } assertEquals(1, nullCount); assertEquals(1, oneCount); assertEquals(2, twoCount); assertEquals(3, threeCount); assertEquals(4, fourCount); }
public void testSerialization() throws Exception { Association assoc2 = (Association) TestTools.serialize(this.assoc); assertEquals(this.assoc, assoc2); assertNotSame(this.assoc, assoc2); assertEquals(this.assoc.getKey(), assoc2.getKey()); assertNotSame(this.assoc.getKey(), assoc2.getKey()); assertEquals(this.assoc.getValue(), assoc2.getValue()); assertNotSame(this.assoc.getValue(), assoc2.getValue()); }