author | mli |
Wed, 23 May 2018 14:21:14 +0800 | |
changeset 50230 | cae567ae015d |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
1281
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
26 |
* @bug 4631471 4921212 4994637 |
2 | 27 |
* @summary Tests HashMap encoding |
28 |
* @author Sergey Malenkov |
|
29 |
*/ |
|
30 |
||
31 |
import java.util.HashMap; |
|
32 |
import java.util.Map; |
|
33 |
||
34 |
public final class java_util_HashMap extends AbstractTest<Map<String, String>> { |
|
35 |
public static void main(String[] args) { |
|
36 |
new java_util_HashMap().test(true); |
|
37 |
} |
|
38 |
||
1281
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
39 |
@Override |
2 | 40 |
protected Map<String, String> getObject() { |
1281
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
41 |
Map<String, String> map = new HashMap<String, String>(); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
42 |
map.put(null, null); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
43 |
map.put("key", "value"); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
44 |
map.put("key-null", "null-value"); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
45 |
map.put("way", "remove"); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
46 |
return map; |
2 | 47 |
} |
48 |
||
1281
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
49 |
@Override |
2 | 50 |
protected Map<String, String> getAnotherObject() { |
51 |
Map<String, String> map = new HashMap<String, String>(); |
|
52 |
map.put(null, "null-value"); |
|
53 |
map.put("key", "value"); |
|
54 |
map.put("key-null", null); |
|
55 |
return map; |
|
56 |
} |
|
57 |
||
1281
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
58 |
@Override |
2 | 59 |
protected void validate(Map<String, String> before, Map<String, String> after) { |
60 |
super.validate(before, after); |
|
61 |
validate(before); |
|
62 |
validate(after); |
|
63 |
} |
|
64 |
||
65 |
private static void validate(Map<String, String> map) { |
|
1281
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
66 |
switch (map.size()) { |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
67 |
case 3: |
2 | 68 |
validate(map, null, "null-value"); |
69 |
validate(map, "key", "value"); |
|
70 |
validate(map, "key-null", null); |
|
1281
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
71 |
break; |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
72 |
case 4: |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
73 |
validate(map, null, null); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
74 |
validate(map, "key", "value"); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
75 |
validate(map, "key-null", "null-value"); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
76 |
validate(map, "way", "remove"); |
b2928adc218e
4994637: LTP: java.beans.java_util_Map_PersistenceDelegate: ConcurrentModificationException
malenkov
parents:
2
diff
changeset
|
77 |
break; |
2 | 78 |
} |
79 |
} |
|
80 |
||
81 |
private static void validate(Map<String, String> map, String key, String value) { |
|
82 |
if (!map.containsKey(key)) |
|
83 |
throw new Error("There are no key: " + key); |
|
84 |
||
85 |
if (!map.containsValue(value)) |
|
86 |
throw new Error("There are no value: " + value); |
|
87 |
||
88 |
if (!isEqual(value, map.get(key))) |
|
89 |
throw new Error("There are no entry: " + key + ", " + value); |
|
90 |
} |
|
91 |
||
92 |
private static boolean isEqual(String str1, String str2) { |
|
93 |
return (str1 == null) |
|
94 |
? str2 == null |
|
95 |
: str1.equals(str2); |
|
96 |
} |
|
97 |
} |