1 /*
2 * Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 package jdk.internal.vm.compiler.collections.test;
26
27 import java.util.Arrays;
28 import java.util.Iterator;
29
30 import jdk.internal.vm.compiler.collections.EconomicMap;
31 import jdk.internal.vm.compiler.collections.EconomicSet;
32 import jdk.internal.vm.compiler.collections.Equivalence;
33 import jdk.internal.vm.compiler.collections.UnmodifiableEconomicSet;
34 import org.junit.Assert;
35 import org.junit.Test;
36
37 public class EconomicMapImplTest {
38
39 @Test(expected = UnsupportedOperationException.class)
40 public void testRemoveNull() {
41 EconomicMap<Integer, Integer> map = EconomicMap.create(10);
42 map.removeKey(null);
43 }
44
100 Assert.assertEquals(newSet.size(), 8);
101 }
102
103 @Test
104 public void testNewEquivalence() {
105 EconomicSet<Integer> set = EconomicSet.create(new Equivalence() {
106 @Override
107 public boolean equals(Object a, Object b) {
108 return false;
109 }
110
111 @Override
112 public int hashCode(Object o) {
113 return 0;
114 }
115 });
116 set.addAll(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
117 Assert.assertTrue(set.add(newInteger(0)));
118 }
119
120 @SuppressWarnings("deprecation")
121 private static Integer newInteger(int value) {
122 return new Integer(value);
123 }
124
125 @Test(expected = UnsupportedOperationException.class)
126 public void testMapPutNull() {
127 EconomicMap<Integer, Integer> map = EconomicMap.create();
128 map.put(null, null);
129 }
130
131 }
|
1 /*
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 package jdk.internal.vm.compiler.collections.test;
42
43 import java.util.Arrays;
44 import java.util.Iterator;
45
46 import jdk.internal.vm.compiler.collections.EconomicMap;
47 import jdk.internal.vm.compiler.collections.EconomicSet;
48 import jdk.internal.vm.compiler.collections.Equivalence;
49 import jdk.internal.vm.compiler.collections.UnmodifiableEconomicSet;
50 import org.junit.Assert;
51 import org.junit.Test;
52
53 public class EconomicMapImplTest {
54
55 @Test(expected = UnsupportedOperationException.class)
56 public void testRemoveNull() {
57 EconomicMap<Integer, Integer> map = EconomicMap.create(10);
58 map.removeKey(null);
59 }
60
116 Assert.assertEquals(newSet.size(), 8);
117 }
118
119 @Test
120 public void testNewEquivalence() {
121 EconomicSet<Integer> set = EconomicSet.create(new Equivalence() {
122 @Override
123 public boolean equals(Object a, Object b) {
124 return false;
125 }
126
127 @Override
128 public int hashCode(Object o) {
129 return 0;
130 }
131 });
132 set.addAll(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
133 Assert.assertTrue(set.add(newInteger(0)));
134 }
135
136 @SuppressWarnings({"deprecation", "unused"})
137 private static Integer newInteger(int value) {
138 return new Integer(value);
139 }
140
141 @Test(expected = UnsupportedOperationException.class)
142 public void testMapPutNull() {
143 EconomicMap<Integer, Integer> map = EconomicMap.create();
144 map.put(null, null);
145 }
146
147 }
|