commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/bag AbstractTestBag.java
Date Wed, 24 Dec 2003 23:09:26 GMT
scolebourne    2003/12/24 15:09:26

  Modified:    collections/src/java/org/apache/commons/collections/bag
                        AbstractMapBag.java
               collections/src/test/org/apache/commons/collections/bag
                        AbstractTestBag.java
  Log:
  Update serialization handling with tests
  
  Revision  Changes    Path
  1.6       +6 -5      jakarta-commons/collections/src/java/org/apache/commons/collections/bag/AbstractMapBag.java
  
  Index: AbstractMapBag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bag/AbstractMapBag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractMapBag.java	7 Dec 2003 01:15:36 -0000	1.5
  +++ AbstractMapBag.java	24 Dec 2003 23:09:26 -0000	1.6
  @@ -518,9 +518,10 @@
           this.map = map;
           int entrySize = in.readInt();
           for (int i = 0; i < entrySize; i++) {
  -            Object key = in.readObject();
  -            int value = in.readInt();
  -            map.put(key, new MutableInteger(value));
  +            Object obj = in.readObject();
  +            int count = in.readInt();
  +            map.put(obj, new MutableInteger(count));
  +            size += count;
           }
       }
       
  
  
  
  1.4       +65 -2     jakarta-commons/collections/src/test/org/apache/commons/collections/bag/AbstractTestBag.java
  
  Index: AbstractTestBag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/bag/AbstractTestBag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractTestBag.java	2 Dec 2003 23:36:12 -0000	1.3
  +++ AbstractTestBag.java	24 Dec 2003 23:09:26 -0000	1.4
  @@ -57,6 +57,8 @@
    */
   package org.apache.commons.collections.bag;
   
  +import java.io.IOException;
  +import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.ConcurrentModificationException;
   import java.util.Iterator;
  @@ -397,4 +399,65 @@
           assertEquals(1, c);
       }
   
  +    //-----------------------------------------------------------------------
  +    public void testEmptyBagSerialization() throws IOException, ClassNotFoundException
{
  +        Bag bag = makeBag();
  +        if (!(bag instanceof Serializable)) return;
  +        
  +        byte[] objekt = writeExternalFormToBytes((Serializable) bag);
  +        Bag bag2 = (Bag) readExternalFormFromBytes(objekt);
  +
  +        assertEquals("Bag should be empty",0, bag.size());
  +        assertEquals("Bag should be empty",0, bag2.size());
  +    }
  +
  +    public void testFullBagSerialization() throws IOException, ClassNotFoundException {
  +        Bag bag = makeBag();
  +        bag.add("A");
  +        bag.add("A");
  +        bag.add("B");
  +        bag.add("B");
  +        bag.add("C");
  +        int size = bag.size();
  +        if (!(bag instanceof Serializable)) return;
  +        
  +        byte[] objekt = writeExternalFormToBytes((Serializable) bag);
  +        Bag bag2 = (Bag) readExternalFormFromBytes(objekt);
  +
  +        assertEquals("Bag should be same size", size, bag.size());
  +        assertEquals("Bag should be same size", size, bag2.size());
  +    }
  +
  +    /**
  +     * Compare the current serialized form of the Bag
  +     * against the canonical version in CVS.
  +     */
  +    public void testEmptyBagCompatibility() throws IOException, ClassNotFoundException
{
  +        // test to make sure the canonical form has been preserved
  +        Bag bag = makeBag();
  +        if(bag instanceof Serializable && !skipSerializedCanonicalTests()) {
  +            Bag bag2 = (Bag) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
  +            assertTrue("Bag is empty",bag2.size()  == 0);
  +            assertEquals(bag, bag2);
  +        }
  +    }
  +
  +    /**
  +     * Compare the current serialized form of the Bag
  +     * against the canonical version in CVS.
  +     */
  +    public void testFullBagCompatibility() throws IOException, ClassNotFoundException {
  +        // test to make sure the canonical form has been preserved
  +        Bag bag = makeBag();
  +        bag.add("A");
  +        bag.add("A");
  +        bag.add("B");
  +        bag.add("B");
  +        bag.add("C");
  +        if(bag instanceof Serializable && !skipSerializedCanonicalTests()) {
  +            Bag bag2 = (Bag) readExternalFormFromDisk(getCanonicalFullCollectionName(bag));
  +            assertEquals("Bag is the right size",bag.size(), bag2.size());
  +            assertEquals(bag, bag2);
  +        }
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message