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.features.CollectionFeature;
     20 import com.google.common.collect.testing.features.Feature;
     21 import com.google.common.collect.testing.testers.ListAddAllAtIndexTester;
     22 import com.google.common.collect.testing.testers.ListAddAllTester;
     23 import com.google.common.collect.testing.testers.ListAddAtIndexTester;
     24 import com.google.common.collect.testing.testers.ListAddTester;
     25 import com.google.common.collect.testing.testers.ListCreationTester;
     26 import com.google.common.collect.testing.testers.ListEqualsTester;
     27 import com.google.common.collect.testing.testers.ListGetTester;
     28 import com.google.common.collect.testing.testers.ListHashCodeTester;
     29 import com.google.common.collect.testing.testers.ListIndexOfTester;
     30 import com.google.common.collect.testing.testers.ListLastIndexOfTester;
     31 import com.google.common.collect.testing.testers.ListListIteratorTester;
     32 import com.google.common.collect.testing.testers.ListRemoveAllTester;
     33 import com.google.common.collect.testing.testers.ListRemoveAtIndexTester;
     34 import com.google.common.collect.testing.testers.ListRemoveTester;
     35 import com.google.common.collect.testing.testers.ListRetainAllTester;
     36 import com.google.common.collect.testing.testers.ListSetTester;
     37 import com.google.common.collect.testing.testers.ListSubListTester;
     38 import com.google.common.collect.testing.testers.ListToArrayTester;
     39 
     40 import junit.framework.TestSuite;
     41 
     42 import java.util.List;
     43 
     44 /**
     45  * Creates, based on your criteria, a JUnit test suite that exhaustively tests
     46  * a List implementation.
     47  *
     48  * @author George van den Driessche
     49  */
     50 public final class ListTestSuiteBuilder<E> extends
     51     AbstractCollectionTestSuiteBuilder<ListTestSuiteBuilder<E>, E> {
     52   public static <E> ListTestSuiteBuilder<E> using(
     53       TestListGenerator<E> generator) {
     54     return new ListTestSuiteBuilder<E>().usingGenerator(generator);
     55   }
     56 
     57   @Override protected List<Class<? extends AbstractTester>> getTesters() {
     58     List<Class<? extends AbstractTester>> testers
     59         = Helpers.copyToList(super.getTesters());
     60 
     61     testers.add(ListAddAllAtIndexTester.class);
     62     testers.add(ListAddAllTester.class);
     63     testers.add(ListAddAtIndexTester.class);
     64     testers.add(ListAddTester.class);
     65     testers.add(ListCreationTester.class);
     66     testers.add(ListEqualsTester.class);
     67     testers.add(ListGetTester.class);
     68     testers.add(ListHashCodeTester.class);
     69     testers.add(ListIndexOfTester.class);
     70     testers.add(ListLastIndexOfTester.class);
     71     testers.add(ListListIteratorTester.class);
     72     testers.add(ListRemoveAllTester.class);
     73     testers.add(ListRemoveAtIndexTester.class);
     74     testers.add(ListRemoveTester.class);
     75     testers.add(ListRetainAllTester.class);
     76     testers.add(ListSetTester.class);
     77     testers.add(ListSubListTester.class);
     78     testers.add(ListToArrayTester.class);
     79     return testers;
     80   }
     81 
     82   /**
     83    * Specifies {@link CollectionFeature#KNOWN_ORDER} for all list tests, since
     84    * lists have an iteration ordering corresponding to the insertion order.
     85    */
     86   @Override public TestSuite createTestSuite() {
     87     if (!getFeatures().contains(CollectionFeature.KNOWN_ORDER)) {
     88       List<Feature<?>> features = Helpers.copyToList(getFeatures());
     89       features.add(CollectionFeature.KNOWN_ORDER);
     90       withFeatures(features);
     91     }
     92     return super.createTestSuite();
     93   }
     94 }
     95