Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      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 
     18 package libcore.java.util.tests;
     19 
     20 import com.google.common.collect.testing.TestsForMapsInJavaUtil;
     21 import com.google.common.collect.testing.testers.CollectionAddAllTester;
     22 import com.google.common.collect.testing.testers.CollectionAddTester;
     23 
     24 import junit.framework.Test;
     25 import junit.framework.TestSuite;
     26 
     27 import java.lang.reflect.Method;
     28 import java.util.Arrays;
     29 import java.util.Collection;
     30 import java.util.Objects;
     31 
     32 /**
     33  * Guava-testlib tests for {@link MapsToTest} that were specified as a
     34  * constructor argument.
     35  */
     36 public class AndroidTestsForMapsInJavaUtil extends TestsForMapsInJavaUtil {
     37     public enum MapsToTest {
     38         /** All Maps other than those below. */
     39         OTHER,
     40         /** TreeMao with natural ordering. */
     41         TREE_MAP_NATURAL,
     42         /** TreeMap with a Comparator. */
     43         TREE_MAP_WITH_COMPARATOR,
     44         /** ConcurrentSKipListMap with natural ordering. */
     45         CONCURRENT_SKIP_LIST_MAP_NATURAL,
     46         /** ConcurrentSKipListMap with a Comparator. */
     47         CONCURRENT_SKIP_LIST_MAP_WITH_COMPARATOR
     48     }
     49 
     50     private final MapsToTest mapsToTest;
     51 
     52     public AndroidTestsForMapsInJavaUtil(MapsToTest mapsToTest) {
     53         this.mapsToTest = Objects.requireNonNull(mapsToTest);
     54     }
     55 
     56     /**
     57      * Returns the tests for the {@link MapsToTest} from {@code java.util}.
     58      */
     59     @Override
     60     public final Test allTests() {
     61         TestSuite suite = new TestSuite("java.util Maps: " + mapsToTest);
     62         switch (mapsToTest) {
     63             case OTHER:
     64                 suite.addTest(testsForCheckedMap());
     65                 suite.addTest(testsForCheckedSortedMap());
     66                 suite.addTest(testsForEmptyMap());
     67                 suite.addTest(testsForSingletonMap());
     68                 suite.addTest(testsForHashMap());
     69                 suite.addTest(testsForLinkedHashMap());
     70                 suite.addTest(testsForEnumMap());
     71                 suite.addTest(testsForConcurrentHashMap());
     72                 break;
     73             case TREE_MAP_NATURAL:
     74                 suite.addTest(testsForTreeMapNatural());
     75                 break;
     76             case TREE_MAP_WITH_COMPARATOR:
     77                 suite.addTest(testsForTreeMapWithComparator());
     78                 break;
     79             case CONCURRENT_SKIP_LIST_MAP_NATURAL:
     80                 suite.addTest(testsForConcurrentSkipListMapNatural());
     81                 break;
     82             case CONCURRENT_SKIP_LIST_MAP_WITH_COMPARATOR:
     83                 suite.addTest(testsForConcurrentSkipListMapWithComparator());
     84                 break;
     85             default:
     86                 throw new IllegalArgumentException("Unknown part: " + mapsToTest);
     87         }
     88         return suite;
     89     }
     90 
     91     @Override
     92     protected final Collection<Method> suppressForConcurrentHashMap() {
     93         // http://b/30853241
     94         return Arrays.asList(
     95                 CollectionAddAllTester.getAddAllUnsupportedNonePresentMethod(),
     96                 CollectionAddAllTester.getAddAllUnsupportedSomePresentMethod(),
     97                 CollectionAddTester.getAddUnsupportedNotPresentMethod());
     98     }
     99 }
    100