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 java.util.ArrayList; 026import java.util.List; 027 028/** 029 * Creates, based on your criteria, a JUnit test suite that exhaustively tests a queue 030 * implementation. 031 * 032 * @author Jared Levy 033 */ 034@GwtIncompatible 035public final class QueueTestSuiteBuilder<E> 036 extends AbstractCollectionTestSuiteBuilder<QueueTestSuiteBuilder<E>, E> { 037 public static <E> QueueTestSuiteBuilder<E> using(TestQueueGenerator<E> generator) { 038 return new QueueTestSuiteBuilder<E>().usingGenerator(generator); 039 } 040 041 private boolean runCollectionTests = true; 042 043 /** 044 * Specify whether to skip the general collection tests. Call this method when testing a 045 * collection that's both a queue and a list, to avoid running the common collection tests twice. 046 * By default, collection tests do run. 047 */ 048 public QueueTestSuiteBuilder<E> skipCollectionTests() { 049 runCollectionTests = false; 050 return this; 051 } 052 053 @Override 054 protected List<Class<? extends AbstractTester>> getTesters() { 055 List<Class<? extends AbstractTester>> testers = new ArrayList<>(); 056 if (runCollectionTests) { 057 testers.addAll(super.getTesters()); 058 } 059 060 testers.add(QueueElementTester.class); 061 testers.add(QueueOfferTester.class); 062 testers.add(QueuePeekTester.class); 063 testers.add(QueuePollTester.class); 064 testers.add(QueueRemoveTester.class); 065 return testers; 066 } 067}