author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 49765 | ee6f7a61f3a5 |
permissions | -rw-r--r-- |
37720 | 1 |
/* |
49765 | 2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
37720 | 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 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
24 |
import java.util.AbstractMap; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
25 |
import java.util.Collection; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
26 |
import java.util.Comparator; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
27 |
import java.util.HashMap; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
28 |
import java.util.Iterator; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
29 |
import java.util.List; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
30 |
import java.util.ListIterator; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
31 |
import java.util.Map; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
32 |
import java.util.Objects; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
33 |
import java.util.Set; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
34 |
import java.util.function.Supplier; |
37720 | 35 |
import java.util.regex.Pattern; |
36 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
37 |
import static java.util.Collections.emptyList; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
38 |
import static java.util.Collections.singleton; |
37720 | 39 |
import static java.util.Objects.requireNonNull; |
40 |
||
41 |
// |
|
42 |
// A set of testing utility functions |
|
43 |
// |
|
44 |
public final class TestKit { |
|
45 |
||
46 |
private TestKit() { } |
|
47 |
||
48 |
public static void assertNotThrows(ThrowingProcedure code) { |
|
49 |
requireNonNull(code, "code"); |
|
50 |
assertNotThrows(() -> { |
|
51 |
code.run(); |
|
52 |
return null; |
|
53 |
}); |
|
54 |
} |
|
55 |
||
56 |
public static <V> V assertNotThrows(ThrowingFunction<V> code) { |
|
57 |
requireNonNull(code, "code"); |
|
58 |
try { |
|
59 |
return code.run(); |
|
60 |
} catch (Throwable t) { |
|
61 |
throw new RuntimeException("Expected to run normally, but threw " |
|
62 |
+ t.getClass().getCanonicalName(), t); |
|
63 |
} |
|
64 |
} |
|
65 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
66 |
public static <T extends Throwable> T assertThrows(Class<T> clazz, |
37720 | 67 |
ThrowingProcedure code) { |
68 |
requireNonNull(clazz, "clazz"); |
|
69 |
requireNonNull(code, "code"); |
|
70 |
try { |
|
71 |
code.run(); |
|
72 |
} catch (Throwable t) { |
|
73 |
if (clazz.isInstance(t)) { |
|
74 |
return clazz.cast(t); |
|
75 |
} |
|
76 |
throw new RuntimeException("Expected to catch an exception of type " |
|
77 |
+ clazz.getCanonicalName() + ", but caught " |
|
78 |
+ t.getClass().getCanonicalName(), t); |
|
79 |
||
80 |
} |
|
81 |
throw new RuntimeException("Expected to catch an exception of type " |
|
82 |
+ clazz.getCanonicalName() + ", but caught nothing"); |
|
83 |
} |
|
84 |
||
85 |
public interface ThrowingProcedure { |
|
86 |
void run() throws Throwable; |
|
87 |
} |
|
88 |
||
89 |
public interface ThrowingFunction<V> { |
|
90 |
V run() throws Throwable; |
|
91 |
} |
|
92 |
||
93 |
// The rationale behind asking for a regex is to not pollute variable names |
|
94 |
// space in the scope of assertion: if it's something as simple as checking |
|
95 |
// a message, we can do it inside |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
96 |
public static <T extends Throwable> T assertThrows(Class<T> clazz, |
37720 | 97 |
String messageRegex, |
98 |
ThrowingProcedure code) { |
|
99 |
requireNonNull(messageRegex, "messagePattern"); |
|
100 |
T t = assertThrows(clazz, code); |
|
101 |
String m = t.getMessage(); |
|
102 |
if (m == null) { |
|
103 |
throw new RuntimeException(String.format( |
|
104 |
"Expected exception message to match the regex '%s', " + |
|
105 |
"but the message was null", messageRegex), t); |
|
106 |
} |
|
107 |
if (!Pattern.matches(messageRegex, m)) { |
|
108 |
throw new RuntimeException(String.format( |
|
109 |
"Expected exception message to match the regex '%s', " + |
|
110 |
"actual message: %s", messageRegex, m), t); |
|
111 |
} |
|
112 |
return t; |
|
113 |
} |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
114 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
115 |
/* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
116 |
* Asserts that the given Collection is unmodifiable: any mutator method |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
117 |
* throw an UnsupportedOperationException unconditionally. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
118 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
119 |
public static void assertUnmodifiableCollection(Collection<?> collection) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
120 |
assertUnmodifiableCollection(collection, () -> null); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
121 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
122 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
123 |
public static <E> void assertUnmodifiableCollection(Collection<E> collection, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
124 |
Supplier<? extends E> elementsFactory) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
125 |
requireNonNull(collection, "collection"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
126 |
requireNonNull(elementsFactory, "elementsFactory"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
127 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
128 |
E e = elementsFactory.get(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
129 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
130 |
assertUOE(() -> collection.add(e)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
131 |
assertUOE(() -> collection.addAll(singleton(e))); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
132 |
Iterator<?> i = collection.iterator(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
133 |
if (i.hasNext()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
134 |
i.next(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
135 |
assertUOE(i::remove); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
136 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
137 |
assertUOE(collection::clear); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
138 |
assertUOE(() -> collection.remove(e)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
139 |
assertUOE(() -> collection.removeAll(singleton(e))); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
140 |
assertUOE(() -> collection.removeIf(x -> true)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
141 |
assertUOE(() -> collection.retainAll(emptyList())); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
142 |
// No need to check toArray methods, since API guarantees arrays |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
143 |
// returned by them are "safe" |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
144 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
145 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
146 |
public static void assertUnmodifiableSet(Set<?> set) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
147 |
assertUnmodifiableCollection(set, () -> null); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
148 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
149 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
150 |
public static <E> void assertUnmodifiableSet(Set<E> set, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
151 |
Supplier<? extends E> elementsFactory) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
152 |
assertUnmodifiableCollection(set, elementsFactory); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
153 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
154 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
155 |
public static void assertUnmodifiableList(List<?> list) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
156 |
assertUnmodifiableList(list, () -> null); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
157 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
158 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
159 |
public static <E> void assertUnmodifiableList(List<E> list, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
160 |
Supplier<? extends E> elementsFactory) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
161 |
assertUnmodifiableList(list, elementsFactory, 3); // This list, its sublist and its sublist's sublist |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
162 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
163 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
164 |
private static <E> void assertUnmodifiableList(List<E> list, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
165 |
Supplier<? extends E> elementsFactory, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
166 |
int depth) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
167 |
requireNonNull(list, "list"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
168 |
requireNonNull(elementsFactory, "elementsFactory"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
169 |
if (depth < 0) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
170 |
throw new IllegalArgumentException("depth: " + depth); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
171 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
172 |
if (depth == 0) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
173 |
return; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
174 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
175 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
176 |
E e = elementsFactory.get(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
177 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
178 |
assertUnmodifiableCollection(list, elementsFactory); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
179 |
assertUOE(() -> list.add(0, e)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
180 |
assertUOE(() -> list.addAll(0, singleton(e))); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
181 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
182 |
ListIterator<E> i = list.listIterator(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
183 |
if (i.hasNext()) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
184 |
i.next(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
185 |
assertUOE(i::remove); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
186 |
assertUOE(() -> i.set(e)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
187 |
assertUOE(() -> i.add(e)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
188 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
189 |
assertUOE(() -> list.remove((int) 0)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
190 |
assertUOE(() -> list.replaceAll(x -> e)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
191 |
assertUOE(() -> list.set(0, e)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
192 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
193 |
// Any non-null general-purpose Comparator would do |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
194 |
Comparator<Object> comparator = (a, b) -> Objects.hash(a, b); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
195 |
assertUOE(() -> list.sort(comparator)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
196 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
197 |
assertUnmodifiableList(list.subList(0, list.size()), elementsFactory, depth - 1); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
198 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
199 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
200 |
public static void assertUnmodifiableMap(Map<?, ?> map) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
201 |
assertUnmodifiableMap(map, () -> new AbstractMap.SimpleImmutableEntry<>(null, null)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
202 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
203 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
204 |
public static <K, V> void assertUnmodifiableMap(Map<K, V> map, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
205 |
Supplier<? extends Map.Entry<? extends K, ? extends V>> entriesFactory) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
206 |
requireNonNull(map, "map"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
207 |
requireNonNull(entriesFactory, "entriesFactory"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
208 |
assertUOE(map::clear); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
209 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
210 |
Map.Entry<? extends K, ? extends V> e1 = entriesFactory.get(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
211 |
K k = e1.getKey(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
212 |
V v = e1.getValue(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
213 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
214 |
assertUOE(() -> map.compute(k, (k1, v1) -> v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
215 |
assertUOE(() -> map.computeIfAbsent(k, (k1) -> v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
216 |
assertUOE(() -> map.computeIfPresent(k, (k1, v1) -> v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
217 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
218 |
Set<Map.Entry<K, V>> entrySet = map.entrySet(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
219 |
assertUnmodifiableSet(entrySet); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
220 |
for (Map.Entry<K, V> e : entrySet) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
221 |
assertUOE(() -> e.setValue(null)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
222 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
223 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
224 |
assertUnmodifiableSet(map.keySet()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
225 |
assertUOE(() -> map.merge(k, v, (k1, v1) -> v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
226 |
assertUOE(() -> map.put(k, v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
227 |
// Map.of(k, v) wouldn't do, as it doesn't permit nulls |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
228 |
Map<K, V> m = new HashMap<>(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
229 |
m.put(k, v); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
230 |
assertUOE(() -> map.putAll(m)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
231 |
assertUOE(() -> map.putIfAbsent(k, v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
232 |
assertUOE(() -> map.remove(k)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
233 |
assertUOE(() -> map.remove(k, v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
234 |
assertUOE(() -> map.replace(k, v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
235 |
assertUOE(() -> map.replace(k, v, v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
236 |
assertUOE(() -> map.replaceAll((k1, v1) -> v)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
237 |
assertUnmodifiableCollection(map.values()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
238 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
239 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
240 |
public static void assertUOE(ThrowingProcedure code) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
241 |
assertThrows(UnsupportedOperationException.class, code); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37720
diff
changeset
|
242 |
} |
37720 | 243 |
} |