1/*
2 * Copyright (C) 2012 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
17package com.google.common.collect;
18
19import java.util.Collections;
20import java.util.Deque;
21
22/**
23 * Tests for {@code ForwardingDeque}.
24 *
25 * @author Kurt Alfred Kluever
26 */
27public class ForwardingDequeTest extends ForwardingTestCase {
28  private Deque<String> forward;
29
30  /*
31   * Class parameters must be raw, so we can't create a proxy with generic
32   * type arguments. The created proxy only records calls and returns null, so
33   * the type is irrelevant at runtime.
34   */
35  @SuppressWarnings("unchecked")
36  @Override protected void setUp() throws Exception {
37    super.setUp();
38    final Deque<String> deque = createProxyInstance(Deque.class);
39    forward = new ForwardingDeque<String>() {
40      @Override protected Deque<String> delegate() {
41        return deque;
42      }
43    };
44  }
45
46  public void testAdd_T() {
47    forward.add("asdf");
48    assertEquals("[add(Object)]", getCalls());
49  }
50
51  public void testAddFirst_T() {
52    forward.addFirst("asdf");
53    assertEquals("[addFirst(Object)]", getCalls());
54  }
55
56  public void testAddLast_T() {
57    forward.addLast("asdf");
58    assertEquals("[addLast(Object)]", getCalls());
59  }
60
61  public void testAddAll_Collection() {
62    forward.addAll(Collections.singleton("asdf"));
63    assertEquals("[addAll(Collection)]", getCalls());
64  }
65
66  public void testClear() {
67    forward.clear();
68    assertEquals("[clear]", getCalls());
69  }
70
71  public void testContains_T() {
72    forward.contains("asdf");
73    assertEquals("[contains(Object)]", getCalls());
74  }
75
76  public void testContainsAll_Collection() {
77    forward.containsAll(Collections.singleton("asdf"));
78    assertEquals("[containsAll(Collection)]", getCalls());
79  }
80
81  public void testDescendingIterator() {
82    forward.descendingIterator();
83    assertEquals("[descendingIterator]", getCalls());
84  }
85
86  public void testElement() {
87    forward.element();
88    assertEquals("[element]", getCalls());
89  }
90
91  public void testGetFirst() {
92    forward.getFirst();
93    assertEquals("[getFirst]", getCalls());
94  }
95
96  public void testGetLast() {
97    forward.getLast();
98    assertEquals("[getLast]", getCalls());
99  }
100
101  public void testIterator() {
102    forward.iterator();
103    assertEquals("[iterator]", getCalls());
104  }
105
106  public void testIsEmpty() {
107    forward.isEmpty();
108    assertEquals("[isEmpty]", getCalls());
109  }
110
111  public void testOffer_T() {
112    forward.offer("asdf");
113    assertEquals("[offer(Object)]", getCalls());
114  }
115
116  public void testOfferFirst_T() {
117    forward.offerFirst("asdf");
118    assertEquals("[offerFirst(Object)]", getCalls());
119  }
120
121  public void testOfferLast_T() {
122    forward.offerLast("asdf");
123    assertEquals("[offerLast(Object)]", getCalls());
124  }
125
126  public void testPeek() {
127    forward.peek();
128    assertEquals("[peek]", getCalls());
129  }
130
131  public void testPeekFirst() {
132    forward.peekFirst();
133    assertEquals("[peekFirst]", getCalls());
134  }
135
136  public void testPeekLast() {
137    forward.peekLast();
138    assertEquals("[peekLast]", getCalls());
139  }
140
141  public void testPoll() {
142    forward.poll();
143    assertEquals("[poll]", getCalls());
144  }
145
146  public void testPollFirst() {
147    forward.pollFirst();
148    assertEquals("[pollFirst]", getCalls());
149  }
150
151  public void testPollLast() {
152    forward.pollLast();
153    assertEquals("[pollLast]", getCalls());
154  }
155
156  public void testPop() {
157    forward.pop();
158    assertEquals("[pop]", getCalls());
159  }
160
161  public void testPush_Object() {
162    forward.push("asdf");
163    assertEquals("[push(Object)]", getCalls());
164  }
165
166  public void testRemove() {
167    forward.remove();
168    assertEquals("[remove]", getCalls());
169  }
170
171  public void testRemoveFirst() {
172    forward.removeFirst();
173    assertEquals("[removeFirst]", getCalls());
174  }
175
176  public void testRemoveLast() {
177    forward.removeLast();
178    assertEquals("[removeLast]", getCalls());
179  }
180
181  public void testRemove_Object() {
182    forward.remove(Object.class);
183    assertEquals("[remove(Object)]", getCalls());
184  }
185
186  public void testRemoveFirstOccurrence_Object() {
187    forward.removeFirstOccurrence(Object.class);
188    assertEquals("[removeFirstOccurrence(Object)]", getCalls());
189  }
190
191  public void testRemoveLastOccurrence_Object() {
192    forward.removeLastOccurrence(Object.class);
193    assertEquals("[removeLastOccurrence(Object)]", getCalls());
194  }
195
196  public void testRemoveAll_Collection() {
197    forward.removeAll(Collections.singleton("asdf"));
198    assertEquals("[removeAll(Collection)]", getCalls());
199  }
200
201  public void testRetainAll_Collection() {
202    forward.retainAll(Collections.singleton("asdf"));
203    assertEquals("[retainAll(Collection)]", getCalls());
204  }
205
206  public void testSize() {
207    forward.size();
208    assertEquals("[size]", getCalls());
209  }
210
211  public void testToArray() {
212    forward.toArray();
213    assertEquals("[toArray]", getCalls());
214  }
215
216  public void testToArray_TArray() {
217    forward.toArray(new String[0]);
218    assertEquals("[toArray(Object[])]", getCalls());
219  }
220
221  public void testToString() {
222    forward.toString();
223    assertEquals("[toString]", getCalls());
224  }
225}
226