Home | History | Annotate | Download | only in testing
      1 /*
      2  * Copyright (C) 2008 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.collect.testing.testers.QueueElementTester;
     20 import com.google.common.collect.testing.testers.QueueOfferTester;
     21 import com.google.common.collect.testing.testers.QueuePeekTester;
     22 import com.google.common.collect.testing.testers.QueuePollTester;
     23 import com.google.common.collect.testing.testers.QueueRemoveTester;
     24 
     25 import java.util.ArrayList;
     26 import java.util.List;
     27 
     28 /**
     29  * Creates, based on your criteria, a JUnit test suite that exhaustively tests
     30  * a queue implementation.
     31  *
     32  * @author Jared Levy
     33  */
     34 public final class QueueTestSuiteBuilder<E>
     35     extends AbstractCollectionTestSuiteBuilder<QueueTestSuiteBuilder<E>, E> {
     36   public static <E> QueueTestSuiteBuilder<E> using(
     37       TestQueueGenerator<E> generator) {
     38     return new QueueTestSuiteBuilder<E>().usingGenerator(generator);
     39   }
     40 
     41   private boolean runCollectionTests = true;
     42 
     43   /**
     44    * Specify whether to skip the general collection tests. Call this method when
     45    * testing a collection that's both a queue and a list, to avoid running the
     46    * common collection tests twice. By default, collection tests do run.
     47    */
     48   public QueueTestSuiteBuilder<E> skipCollectionTests() {
     49     runCollectionTests = false;
     50     return this;
     51   }
     52 
     53   @Override protected List<Class<? extends AbstractTester>> getTesters() {
     54     List<Class<? extends AbstractTester>> testers =
     55         new ArrayList<Class<? extends AbstractTester>>();
     56     if (runCollectionTests) {
     57       testers.addAll(super.getTesters());
     58     }
     59 
     60     testers.add(QueueElementTester.class);
     61     testers.add(QueueOfferTester.class);
     62     testers.add(QueuePeekTester.class);
     63     testers.add(QueuePollTester.class);
     64     testers.add(QueueRemoveTester.class);
     65     return testers;
     66   }
     67 }
     68