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.annotations.GwtIncompatible;
     21 import com.google.common.collect.MapConstraintsTest.TestKeyException;
     22 import com.google.common.collect.MapConstraintsTest.TestValueException;
     23 
     24 /**
     25  * Tests for {@link MapConstraints#constrainedBiMap}.
     26  *
     27  * @author Jared Levy
     28  */
     29 @GwtCompatible(emulated = true)
     30 public class ConstrainedBiMapTest extends AbstractBiMapTest {
     31 
     32   private static final Integer TEST_KEY = 42;
     33   private static final String TEST_VALUE = "test";
     34   private static final MapConstraint<Integer, String> TEST_CONSTRAINT
     35       = new TestConstraint();
     36 
     37   private static final class TestConstraint
     38       implements MapConstraint<Integer, String> {
     39     @Override
     40     public void checkKeyValue(Integer key, String value) {
     41       if (TEST_KEY.equals(key)) {
     42         throw new TestKeyException();
     43       }
     44       if (TEST_VALUE.equals(value)) {
     45         throw new TestValueException();
     46       }
     47     }
     48     private static final long serialVersionUID = 0;
     49   }
     50 
     51   @Override protected BiMap<Integer, String> create() {
     52     return MapConstraints.constrainedBiMap(
     53         HashBiMap.<Integer, String>create(), TEST_CONSTRAINT);
     54   }
     55 
     56   // not serializable
     57   @GwtIncompatible("SerializableTester")
     58   @Override
     59   public void testSerialization() {}
     60 
     61   @GwtIncompatible("SerializableTester")
     62   @Override
     63   public void testSerializationWithInverseEqual() {}
     64 
     65   @GwtIncompatible("SerializableTester")
     66   @Override
     67   public void testSerializationWithInverseSame() {}
     68 }
     69