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 17 package com.google.common.collect; 18 19 import java.util.concurrent.BlockingDeque; 20 import java.util.concurrent.TimeUnit; 21 22 /** 23 * Test for {@link ForwardingBlockingDeque} 24 * 25 * @author Emily Soldal 26 */ 27 public class ForwardingBlockingDequeTest extends ForwardingTestCase { 28 private BlockingDeque<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") setUp()36 @Override protected void setUp() throws Exception { 37 super.setUp(); 38 final BlockingDeque<String> deque = createProxyInstance(BlockingDeque.class); 39 forward = new ForwardingBlockingDeque<String>() { 40 @Override protected BlockingDeque<String> delegate() { 41 return deque; 42 } 43 }; 44 } 45 testRemainingCapacity()46 public void testRemainingCapacity() { 47 forward.remainingCapacity(); 48 assertEquals("[remainingCapacity]", getCalls()); 49 } 50 testPutFirst_T()51 public void testPutFirst_T() throws InterruptedException { 52 forward.putFirst("asf"); 53 assertEquals("[putFirst(Object)]", getCalls()); 54 } 55 testPutLast_T()56 public void testPutLast_T() throws InterruptedException { 57 forward.putFirst("asf"); 58 assertEquals("[putFirst(Object)]", getCalls()); 59 } 60 testOfferFirst_T()61 public void testOfferFirst_T() throws InterruptedException { 62 forward.offerFirst("asf", 2L, TimeUnit.SECONDS); 63 assertEquals("[offerFirst(Object,long,TimeUnit)]", getCalls()); 64 } 65 testOfferLast_T()66 public void testOfferLast_T() throws InterruptedException { 67 forward.offerLast("asf", 2L, TimeUnit.SECONDS); 68 assertEquals("[offerLast(Object,long,TimeUnit)]", getCalls()); 69 } 70 testTakeFirst()71 public void testTakeFirst() throws InterruptedException { 72 forward.takeFirst(); 73 assertEquals("[takeFirst]", getCalls()); 74 } 75 testTakeLast()76 public void testTakeLast() throws InterruptedException { 77 forward.takeLast(); 78 assertEquals("[takeLast]", getCalls()); 79 } 80 testPollFirst()81 public void testPollFirst() throws InterruptedException { 82 forward.pollFirst(2L, TimeUnit.SECONDS); 83 assertEquals("[pollFirst(long,TimeUnit)]", getCalls()); 84 } 85 testPollLast()86 public void testPollLast() throws InterruptedException { 87 forward.pollLast(2L, TimeUnit.SECONDS); 88 assertEquals("[pollLast(long,TimeUnit)]", getCalls()); 89 } 90 testPut_T()91 public void testPut_T() throws InterruptedException { 92 forward.put("asf"); 93 assertEquals("[put(Object)]", getCalls()); 94 } 95 testOffer_T()96 public void testOffer_T() throws InterruptedException { 97 forward.offer("asf", 2L, TimeUnit.SECONDS); 98 assertEquals("[offer(Object,long,TimeUnit)]", getCalls()); 99 } 100 testTake()101 public void testTake() throws InterruptedException { 102 forward.take(); 103 assertEquals("[take]", getCalls()); 104 } 105 testPoll()106 public void testPoll() throws InterruptedException { 107 forward.poll(2L, TimeUnit.SECONDS); 108 assertEquals("[poll(long,TimeUnit)]", getCalls()); 109 } 110 testDrainTo_T()111 public void testDrainTo_T() { 112 forward.drainTo(Lists.newArrayList()); 113 assertEquals("[drainTo(Collection)]", getCalls()); 114 } 115 testDrainTo_T_maxElements()116 public void testDrainTo_T_maxElements() { 117 forward.drainTo(Lists.newArrayList(), 3); 118 assertEquals("[drainTo(Collection,int)]", getCalls()); 119 } 120 } 121