Debian Codegraph @

guava-testlib/src/com/google/common/collect/testing/TestsForQueuesInJavaUtil.java

raw
1 /*
2 * Copyright (C) 2009 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.common.collect.testing;
18
19 import com.google.common.annotations.GwtIncompatible;
20 import com.google.common.collect.testing.features.CollectionFeature;
21 import com.google.common.collect.testing.features.CollectionSize;
22 import java.lang.reflect.Method;
23 import java.util.ArrayDeque;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.LinkedList;
27 import java.util.PriorityQueue;
28 import java.util.Queue;
29 import java.util.concurrent.ArrayBlockingQueue;
30 import java.util.concurrent.ConcurrentLinkedDeque;
31 import java.util.concurrent.ConcurrentLinkedQueue;
32 import java.util.concurrent.LinkedBlockingDeque;
33 import java.util.concurrent.LinkedBlockingQueue;
34 import java.util.concurrent.PriorityBlockingQueue;
35 import junit.framework.Test;
36 import junit.framework.TestSuite;
37
38 /**
39 * Generates a test suite covering the {@link Queue} implementations in the {@link java.util}
40 * package. Can be subclassed to specify tests that should be suppressed.
41 *
42 * @author Jared Levy
43 */
44 @GwtIncompatible
45 public class TestsForQueuesInJavaUtil {
46 public static Test suite() {
47 return new TestsForQueuesInJavaUtil().allTests();
48 }
49
50 public Test allTests() {
51 TestSuite suite = new TestSuite();
52 suite.addTest(testsForArrayDeque());
53 suite.addTest(testsForLinkedList());
54 suite.addTest(testsForArrayBlockingQueue());
55 suite.addTest(testsForCheckedQueue());
56 suite.addTest(testsForConcurrentLinkedDeque());
57 suite.addTest(testsForConcurrentLinkedQueue());
58 suite.addTest(testsForLinkedBlockingDeque());
59 suite.addTest(testsForLinkedBlockingQueue());
60 suite.addTest(testsForPriorityBlockingQueue());
61 suite.addTest(testsForPriorityQueue());
62 return suite;
63 }
64
65 protected Collection<Method> suppressForCheckedQueue() {
66 return Collections.emptySet();
67 }
68
69 protected Collection<Method> suppressForArrayDeque() {
70 return Collections.emptySet();
71 }
72
73 protected Collection<Method> suppressForLinkedList() {
74 return Collections.emptySet();
75 }
76
77 protected Collection<Method> suppressForArrayBlockingQueue() {
78 return Collections.emptySet();
79 }
80
81 protected Collection<Method> suppressForConcurrentLinkedDeque() {
82 return Collections.emptySet();
83 }
84
85 protected Collection<Method> suppressForConcurrentLinkedQueue() {
86 return Collections.emptySet();
87 }
88
89 protected Collection<Method> suppressForLinkedBlockingDeque() {
90 return Collections.emptySet();
91 }
92
93 protected Collection<Method> suppressForLinkedBlockingQueue() {
94 return Collections.emptySet();
95 }
96
97 protected Collection<Method> suppressForPriorityBlockingQueue() {
98 return Collections.emptySet();
99 }
100
101 protected Collection<Method> suppressForPriorityQueue() {
102 return Collections.emptySet();
103 }
104
105 public Test testsForCheckedQueue() {
106 return QueueTestSuiteBuilder.using(
107 new TestStringQueueGenerator() {
108 @Override
109 public Queue<String> create(String[] elements) {
110 Queue<String> queue = new LinkedList<>(MinimalCollection.of(elements));
111 return Collections.checkedQueue(queue, String.class);
112 }
113 })
114 .named("checkedQueue/LinkedList")
115 .withFeatures(
116 CollectionFeature.GENERAL_PURPOSE,
117 CollectionFeature.ALLOWS_NULL_VALUES,
118 CollectionFeature.KNOWN_ORDER,
119 CollectionFeature.RESTRICTS_ELEMENTS,
120 CollectionSize.ANY)
121 // don't skip collection tests since checkedQueue() is not tested by TestsForListsInJavaUtil
122 .suppressing(suppressForCheckedQueue())
123 .createTestSuite();
124 }
125
126 public Test testsForArrayDeque() {
127 return QueueTestSuiteBuilder.using(
128 new TestStringQueueGenerator() {
129 @Override
130 public Queue<String> create(String[] elements) {
131 return new ArrayDeque<>(MinimalCollection.of(elements));
132 }
133 })
134 .named("ArrayDeque")
135 .withFeatures(
136 CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY)
137 .suppressing(suppressForArrayDeque())
138 .createTestSuite();
139 }
140
141 public Test testsForLinkedList() {
142 return QueueTestSuiteBuilder.using(
143 new TestStringQueueGenerator() {
144 @Override
145 public Queue<String> create(String[] elements) {
146 return new LinkedList<>(MinimalCollection.of(elements));
147 }
148 })
149 .named("LinkedList")
150 .withFeatures(
151 CollectionFeature.GENERAL_PURPOSE,
152 CollectionFeature.ALLOWS_NULL_VALUES,
153 CollectionFeature.KNOWN_ORDER,
154 CollectionSize.ANY)
155 .skipCollectionTests() // already covered in TestsForListsInJavaUtil
156 .suppressing(suppressForLinkedList())
157 .createTestSuite();
158 }
159
160 public Test testsForArrayBlockingQueue() {
161 return QueueTestSuiteBuilder.using(
162 new TestStringQueueGenerator() {
163 @Override
164 public Queue<String> create(String[] elements) {
165 return new ArrayBlockingQueue<>(100, false, MinimalCollection.of(elements));
166 }
167 })
168 .named("ArrayBlockingQueue")
169 .withFeatures(
170 CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY)
171 .suppressing(suppressForArrayBlockingQueue())
172 .createTestSuite();
173 }
174
175 public Test testsForConcurrentLinkedDeque() {
176 return QueueTestSuiteBuilder.using(
177 new TestStringQueueGenerator() {
178 @Override
179 public Queue<String> create(String[] elements) {
180 return new ConcurrentLinkedDeque<>(MinimalCollection.of(elements));
181 }
182 })
183 .named("ConcurrentLinkedDeque")
184 .withFeatures(
185 CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY)
186 .suppressing(suppressForConcurrentLinkedDeque())
187 .createTestSuite();
188 }
189
190 public Test testsForConcurrentLinkedQueue() {
191 return QueueTestSuiteBuilder.using(
192 new TestStringQueueGenerator() {
193 @Override
194 public Queue<String> create(String[] elements) {
195 return new ConcurrentLinkedQueue<>(MinimalCollection.of(elements));
196 }
197 })
198 .named("ConcurrentLinkedQueue")
199 .withFeatures(
200 CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY)
201 .suppressing(suppressForConcurrentLinkedQueue())
202 .createTestSuite();
203 }
204
205 public Test testsForLinkedBlockingDeque() {
206 return QueueTestSuiteBuilder.using(
207 new TestStringQueueGenerator() {
208 @Override
209 public Queue<String> create(String[] elements) {
210 return new LinkedBlockingDeque<>(MinimalCollection.of(elements));
211 }
212 })
213 .named("LinkedBlockingDeque")
214 .withFeatures(
215 CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY)
216 .suppressing(suppressForLinkedBlockingDeque())
217 .createTestSuite();
218 }
219
220 public Test testsForLinkedBlockingQueue() {
221 return QueueTestSuiteBuilder.using(
222 new TestStringQueueGenerator() {
223 @Override
224 public Queue<String> create(String[] elements) {
225 return new LinkedBlockingQueue<>(MinimalCollection.of(elements));
226 }
227 })
228 .named("LinkedBlockingQueue")
229 .withFeatures(
230 CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY)
231 .suppressing(suppressForLinkedBlockingQueue())
232 .createTestSuite();
233 }
234
235 // Not specifying KNOWN_ORDER for PriorityQueue and PriorityBlockingQueue
236 // even though they do have it, because our tests interpret KNOWN_ORDER to
237 // also mean that the iterator returns the head element first, which those
238 // don't.
239
240 public Test testsForPriorityBlockingQueue() {
241 return QueueTestSuiteBuilder.using(
242 new TestStringQueueGenerator() {
243 @Override
244 public Queue<String> create(String[] elements) {
245 return new PriorityBlockingQueue<>(MinimalCollection.of(elements));
246 }
247 })
248 .named("PriorityBlockingQueue")
249 .withFeatures(CollectionFeature.GENERAL_PURPOSE, CollectionSize.ANY)
250 .suppressing(suppressForPriorityBlockingQueue())
251 .createTestSuite();
252 }
253
254 public Test testsForPriorityQueue() {
255 return QueueTestSuiteBuilder.using(
256 new TestStringQueueGenerator() {
257 @Override
258 public Queue<String> create(String[] elements) {
259 return new PriorityQueue<>(MinimalCollection.of(elements));
260 }
261 })
262 .named("PriorityQueue")
263 .withFeatures(CollectionFeature.GENERAL_PURPOSE, CollectionSize.ANY)
264 .suppressing(suppressForPriorityQueue())
265 .createTestSuite();
266 }
267 }