001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.collections.primitives.adapters;
018
019import java.io.Serializable;
020import java.util.AbstractList;
021import java.util.ArrayList;
022import java.util.List;
023
024import junit.framework.Test;
025import junit.framework.TestSuite;
026
027import org.apache.commons.collections.AbstractTestObject;
028import org.apache.commons.collections.primitives.IntCollection;
029
030/**
031 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
032 * @author Rodney Waldhoff
033 */
034public class TestCollectionIntCollection extends AbstractTestObject {
035
036    // conventional
037    // ------------------------------------------------------------------------
038
039    public TestCollectionIntCollection(String testName) {
040        super(testName);
041    }
042
043    public static Test suite() {
044        return new TestSuite(TestCollectionIntCollection.class);
045    }
046
047    // collections testing framework
048    // ------------------------------------------------------------------------
049
050    public Object makeObject() {
051        List list = new ArrayList();
052        for(int i=0;i<10;i++) {
053            list.add(new Integer(i));
054        }
055        return new CollectionIntCollection(list);
056    }
057
058    public void testSerializeDeserializeThenCompare() {
059        // Collection.equal contract doesn't work that way
060    }
061
062    /** @TODO need to add serialized form to cvs */
063    public void testCanonicalEmptyCollectionExists() {
064        // XXX FIX ME XXX
065        // need to add a serialized form to cvs
066    }
067
068    public void testCanonicalFullCollectionExists() {
069        // XXX FIX ME XXX
070        // need to add a serialized form to cvs
071    }
072    
073    // tests
074    // ------------------------------------------------------------------------
075
076    public void testWrapNull() {
077        assertNull(CollectionIntCollection.wrap(null));
078    }
079    
080    public void testWrapSerializable() {
081        IntCollection collection = CollectionIntCollection.wrap(new ArrayList());
082        assertNotNull(collection);
083        assertTrue(collection instanceof Serializable);
084    }
085    
086    public void testWrapNonSerializable() {
087        IntCollection collection = CollectionIntCollection.wrap(new AbstractList() { 
088            public Object get(int i) { throw new IndexOutOfBoundsException(); } 
089            public int size() { return 0; } 
090        });
091        assertNotNull(collection);
092        assertTrue(!(collection instanceof Serializable));
093    }
094
095}