1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.queue;
18
19 import java.util.Arrays;
20 import java.util.Collection;
21 import java.util.LinkedList;
22 import java.util.Queue;
23
24 import org.apache.commons.collections4.Unmodifiable;
25 import org.apache.commons.collections4.collection.AbstractCollectionTest;
26
27
28
29
30
31
32
33 public class UnmodifiableQueueTest<E> extends AbstractQueueTest<E> {
34
35 public UnmodifiableQueueTest(final String testName) {
36 super(testName);
37 }
38
39
40 @Override
41 public Queue<E> makeObject() {
42 return UnmodifiableQueue.unmodifiableQueue(new LinkedList<E>());
43 }
44
45 @Override
46 public Queue<E> makeFullCollection() {
47 final Queue<E> queue = new LinkedList<>();
48 queue.addAll(Arrays.asList(getFullElements()));
49 return UnmodifiableQueue.unmodifiableQueue(queue);
50 }
51
52 @Override
53 public Collection<E> makeConfirmedCollection() {
54 return new LinkedList<>();
55 }
56
57 @Override
58 public Collection<E> makeConfirmedFullCollection() {
59 final LinkedList<E> list = new LinkedList<>();
60 list.addAll(Arrays.asList(getFullElements()));
61 return list;
62 }
63
64 @Override
65 public Queue<E> getCollection() {
66 return super.getCollection();
67 }
68
69 @Override
70 public boolean isAddSupported() {
71 return false;
72 }
73
74 @Override
75 public boolean isRemoveSupported() {
76 return false;
77 }
78
79 @Override
80 public boolean isNullSupported() {
81 return false;
82 }
83
84
85 @Override
86 public void testQueueRemove() {
87 resetEmpty();
88 try {
89 getCollection().remove();
90 fail();
91 } catch (final UnsupportedOperationException ex) {}
92 }
93
94 public void testUnmodifiable() {
95 assertTrue(makeObject() instanceof Unmodifiable);
96 assertTrue(makeFullCollection() instanceof Unmodifiable);
97 }
98
99 public void testDecorateFactory() {
100 final Queue<E> queue = makeFullCollection();
101 assertSame(queue, UnmodifiableQueue.unmodifiableQueue(queue));
102
103 try {
104 UnmodifiableQueue.unmodifiableQueue(null);
105 fail();
106 } catch (final NullPointerException ex) {}
107 }
108
109
110
111 @Override
112 public String getCompatibilityVersion() {
113 return "4";
114 }
115
116
117
118
119
120
121
122
123 }