1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package libcore.java.util;
18
19import junit.framework.TestCase;
20
21import java.util.AbstractSequentialList;
22import java.util.AbstractSet;
23import java.util.Collection;
24import java.util.Iterator;
25import java.util.Vector;
26
27public class OldAbstractSetTest extends TestCase {
28
29    class Mock_AbstractSet extends AbstractSet{
30
31        @Override
32        public Iterator iterator() {
33            return new Iterator() {
34                public boolean hasNext() {
35                    return false;
36                }
37
38                public Object next() {
39                    return null;
40                }
41
42                public void remove() {
43                }
44            };
45        }
46
47        @Override
48        public int size() {
49            return 0;
50        }
51    }
52
53    public void testHashCode() {
54        AbstractSet as = new Mock_AbstractSet();
55        assertNotNull(as.hashCode());
56    }
57
58    public void testEquals() {
59        AbstractSet as1 = new Mock_AbstractSet();
60        AbstractSet as2 = new Mock_AbstractSet();
61
62        assertTrue(as1.equals(as2));
63    }
64
65    public void testRemoveAll() {
66        AbstractSet as = new AbstractSet(){
67            @Override
68            public Iterator iterator() {
69                return new Iterator() {
70                    public boolean hasNext() {
71                        return true;
72                    }
73
74                    public Object next() {
75                        return null;
76                    }
77
78                    public void remove() {
79                        throw new UnsupportedOperationException();
80                    }
81
82                };
83            }
84
85            @Override
86            public int size() {
87                return 10;
88            }
89        };
90
91        try {
92            as.removeAll(null);
93            fail("NullPointerException expected");
94        } catch (NullPointerException e) {
95            //expected
96        }
97        Collection c = new Vector();
98        c.add(null);
99        try {
100            as.removeAll(c);
101            fail("UnsupportedOperationException expected");
102        } catch (UnsupportedOperationException e) {
103            //expected
104        }
105
106        as = new Mock_AbstractSet();
107
108        as.removeAll(c);
109    }
110}
111