blob: d6da122d6116505eea231409b1b0a80ad8874ce9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.collections;
import org.junit.Test;
import static org.junit.Assert.fail;
/**
* @author bratseth
*/
public class FreezableArrayListListener {
@Test
public void testPermitAdd() {
FreezableArrayList<String> l = new FreezableArrayList<>(true);
l.add("1");
l.add("2");
l.remove(1);
l.freeze();
try {
l.remove(0);
fail("Expected exception");
}
catch (UnsupportedOperationException expected) {
}
try {
l.set(0, "2");
fail("Expected exception");
}
catch (UnsupportedOperationException expected) {
}
try {
l.add(0, "2");
fail("Expected exception");
}
catch (UnsupportedOperationException expected) {
}
l.add("2");
}
@Test
public void testDontPermitAdd() {
FreezableArrayList<String> l = new FreezableArrayList<>();
l.add("1");
l.add("2");
l.remove(1);
l.freeze();
try {
l.remove(0);
fail("Expected exception");
}
catch (UnsupportedOperationException expected) {
}
try {
l.set(0, "2");
fail("Expected exception");
}
catch (UnsupportedOperationException expected) {
}
try {
l.add(0, "2");
fail("Expected exception");
}
catch (UnsupportedOperationException expected) {
}
try {
l.add("2");
fail("Expected exception");
}
catch (UnsupportedOperationException expected) {
}
}
}
|