Home | History | Annotate | Download | only in collect
      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;
     18 
     19 import com.google.common.annotations.GwtCompatible;
     20 import com.google.common.collect.testing.SetTestSuiteBuilder;
     21 import com.google.common.collect.testing.TestStringSetGenerator;
     22 import com.google.common.collect.testing.features.CollectionFeature;
     23 import com.google.common.collect.testing.features.CollectionSize;
     24 
     25 import junit.framework.Test;
     26 import junit.framework.TestCase;
     27 import junit.framework.TestSuite;
     28 
     29 import java.util.Set;
     30 
     31 /**
     32  * Collection tests for bimaps.
     33  *
     34  * @author Jared Levy
     35  */
     36 @GwtCompatible
     37 public class BiMapCollectionTest extends TestCase {
     38 
     39   public static Test suite() {
     40     TestSuite suite = new TestSuite();
     41     suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
     42           @Override protected Set<String> create(String[] elements) {
     43             BiMap<String, Integer> bimap = HashBiMap.create();
     44             for (int i = 0; i < elements.length; i++) {
     45               bimap.put(elements[i], i);
     46             }
     47             return bimap.keySet();
     48           }
     49         })
     50         .named("HashBiMap.keySet")
     51         .withFeatures(CollectionSize.ANY,
     52             CollectionFeature.ALLOWS_NULL_VALUES,
     53             CollectionFeature.REMOVE_OPERATIONS)
     54         .createTestSuite());
     55 
     56     suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
     57           @Override protected Set<String> create(String[] elements) {
     58             BiMap<Integer, String> bimap = HashBiMap.create();
     59             for (int i = 0; i < elements.length; i++) {
     60               bimap.put(i, elements[i]);
     61             }
     62             return bimap.values();
     63           }
     64         })
     65         .named("HashBiMap.values")
     66         .withFeatures(CollectionSize.ANY,
     67             CollectionFeature.ALLOWS_NULL_VALUES,
     68             CollectionFeature.REMOVE_OPERATIONS,
     69             CollectionFeature.REJECTS_DUPLICATES_AT_CREATION)
     70         .createTestSuite());
     71 
     72     return suite;
     73   }
     74 }
     75