1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
11 |
|
|
12 |
|
public class EntryTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
14 |
< |
junit.textui.TestRunner.run (suite()); |
14 |
> |
junit.textui.TestRunner.run(suite()); |
15 |
|
} |
16 |
|
public static Test suite() { |
17 |
|
return new TestSuite(EntryTest.class); |
22 |
|
static final String k2 = "2"; |
23 |
|
static final String v2 = "b"; |
24 |
|
|
25 |
– |
|
25 |
|
/** |
26 |
|
* A new SimpleEntry(k, v) holds k, v. |
27 |
|
*/ |
40 |
|
assertEquals(v1, s.getValue()); |
41 |
|
} |
42 |
|
|
44 |
– |
|
43 |
|
/** |
44 |
|
* A new SimpleEntry(entry(k, v)) holds k, v. |
45 |
|
*/ |
85 |
|
public void testNotEquals() { |
86 |
|
Map.Entry e2 = new AbstractMap.SimpleEntry(k1, v1); |
87 |
|
Map.Entry e = new AbstractMap.SimpleEntry(k2, v1); |
88 |
< |
assertFalse(e2.equals( e)); |
88 |
> |
assertFalse(e2.equals(e)); |
89 |
|
e = new AbstractMap.SimpleEntry(k1, v2); |
90 |
< |
assertFalse(e2.equals( e)); |
90 |
> |
assertFalse(e2.equals(e)); |
91 |
|
e = new AbstractMap.SimpleEntry(k2, v2); |
92 |
< |
assertFalse(e2.equals( e)); |
92 |
> |
assertFalse(e2.equals(e)); |
93 |
|
|
94 |
|
Map.Entry s2 = new AbstractMap.SimpleImmutableEntry(k1, v1); |
95 |
|
Map.Entry s = new AbstractMap.SimpleImmutableEntry(k2, v1); |
96 |
< |
assertFalse(s2.equals( s)); |
96 |
> |
assertFalse(s2.equals(s)); |
97 |
|
s = new AbstractMap.SimpleImmutableEntry(k1, v2); |
98 |
< |
assertFalse(s2.equals( s)); |
98 |
> |
assertFalse(s2.equals(s)); |
99 |
|
s = new AbstractMap.SimpleImmutableEntry(k2, v2); |
100 |
< |
assertFalse(s2.equals( s)); |
100 |
> |
assertFalse(s2.equals(s)); |
101 |
|
} |
102 |
|
|
105 |
– |
|
103 |
|
/** |
104 |
|
* getValue returns last setValue for SimpleEntry |
105 |
|
*/ |
110 |
|
assertEquals(v1, e.getValue()); |
111 |
|
e.setValue(k2); |
112 |
|
assertEquals(k2, e.getValue()); |
113 |
< |
assertFalse(e2.equals( e)); |
113 |
> |
assertFalse(e2.equals(e)); |
114 |
|
} |
115 |
|
|
116 |
|
/** |
117 |
|
* setValue for SimpleImmutableEntry throws UnsupportedOperationException |
118 |
|
*/ |
119 |
< |
public void testsetValue2() { |
119 |
> |
public void testSetValue2() { |
120 |
|
Map.Entry s2 = new AbstractMap.SimpleImmutableEntry(k1, v1); |
121 |
|
Map.Entry s = new AbstractMap.SimpleImmutableEntry(s2); |
122 |
|
assertEquals(k1, s.getKey()); |
123 |
|
assertEquals(v1, s.getValue()); |
124 |
|
try { |
125 |
|
s.setValue(k2); |
126 |
< |
fail(); |
126 |
> |
shouldThrow(); |
127 |
|
} catch (UnsupportedOperationException success) {} |
128 |
|
} |
129 |
|
} |