001/* 002 * Copyright (C) 2008 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.collect.testing; 018 019import com.google.common.annotations.GwtIncompatible; 020import com.google.common.collect.testing.testers.QueueElementTester; 021import com.google.common.collect.testing.testers.QueueOfferTester; 022import com.google.common.collect.testing.testers.QueuePeekTester; 023import com.google.common.collect.testing.testers.QueuePollTester; 024import com.google.common.collect.testing.testers.QueueRemoveTester; 025import com.google.errorprone.annotations.CanIgnoreReturnValue; 026import java.util.ArrayList; 027import java.util.List; 028 029/** 030 * Creates, based on your criteria, a JUnit test suite that exhaustively tests a queue 031 * implementation. 032 * 033 * @author Jared Levy 034 */ 035@GwtIncompatible 036public final class QueueTestSuiteBuilder<E> 037 extends AbstractCollectionTestSuiteBuilder<QueueTestSuiteBuilder<E>, E> { 038 public static <E> QueueTestSuiteBuilder<E> using(TestQueueGenerator<E> generator) { 039 return new QueueTestSuiteBuilder<E>().usingGenerator(generator); 040 } 041 042 private boolean runCollectionTests = true; 043 044 /** 045 * Specify whether to skip the general collection tests. Call this method when testing a 046 * collection that's both a queue and a list, to avoid running the common collection tests twice. 047 * By default, collection tests do run. 048 */ 049 @CanIgnoreReturnValue 050 public QueueTestSuiteBuilder<E> skipCollectionTests() { 051 runCollectionTests = false; 052 return this; 053 } 054 055 @Override 056 protected List<Class<? extends AbstractTester>> getTesters() { 057 List<Class<? extends AbstractTester>> testers = new ArrayList<>(); 058 if (runCollectionTests) { 059 testers.addAll(super.getTesters()); 060 } 061 062 testers.add(QueueElementTester.class); 063 testers.add(QueueOfferTester.class); 064 testers.add(QueuePeekTester.class); 065 testers.add(QueuePollTester.class); 066 testers.add(QueueRemoveTester.class); 067 return testers; 068 } 069}