SortedSetTestSuiteBuilder.java revision 3c77433663281544363151bf284b0240dfd22a42
1/*
2 * Copyright (C) 2010 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
17package com.google.common.collect.testing;
18
19import com.google.common.collect.testing.features.CollectionFeature;
20import com.google.common.collect.testing.features.Feature;
21import com.google.common.collect.testing.testers.SortedSetNavigationTester;
22
23import junit.framework.TestSuite;
24
25import java.util.List;
26
27/**
28 * Creates, based on your criteria, a JUnit test suite that exhaustively tests
29 * a SortedSet implementation.
30 */
31public class SortedSetTestSuiteBuilder<E> extends SetTestSuiteBuilder<E> {
32  public static <E> SortedSetTestSuiteBuilder<E> using(
33      TestSetGenerator<E> generator) {
34    SortedSetTestSuiteBuilder<E> builder =
35        new SortedSetTestSuiteBuilder<E>();
36    builder.usingGenerator(generator);
37    return builder;
38  }
39
40  @Override protected List<Class<? extends AbstractTester>> getTesters() {
41    List<Class<? extends AbstractTester>> testers =
42        Helpers.copyToList(super.getTesters());
43    testers.add(SortedSetNavigationTester.class);
44    return testers;
45  }
46
47  @Override public TestSuite createTestSuite() {
48    if (!getFeatures().contains(CollectionFeature.KNOWN_ORDER)) {
49      List<Feature<?>> features = Helpers.copyToList(getFeatures());
50      features.add(CollectionFeature.KNOWN_ORDER);
51      withFeatures(features);
52    }
53    return super.createTestSuite();
54  }
55}
56