Coverage Summary for Class: BiMapInverseTester (com.google.common.collect.testing.google)

Class Method, % Line, %
BiMapInverseTester 0% (0/5) 0% (0/12)
BiMapInverseTester$BiMapPair 0% (0/1) 0% (0/3)
Total 0% (0/6) 0% (0/15)


1 /* 2  * Copyright (C) 2012 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.google; 18  19 import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE; 20  21 import com.google.common.annotations.GwtCompatible; 22 import com.google.common.annotations.GwtIncompatible; 23 import com.google.common.collect.BiMap; 24 import com.google.common.collect.testing.Helpers; 25 import com.google.common.collect.testing.features.CollectionFeature; 26 import com.google.common.testing.SerializableTester; 27 import java.io.Serializable; 28 import java.lang.reflect.Method; 29 import java.util.Collections; 30 import java.util.List; 31 import org.junit.Ignore; 32  33 /** 34  * Tests for the {@code inverse} view of a BiMap. 35  * 36  * <p>This assumes that {@code bimap.inverse().inverse() == bimap}, which is not technically 37  * required but is fulfilled by all current implementations. 38  * 39  * @author Louis Wasserman 40  */ 41 @GwtCompatible(emulated = true) 42 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 43 public class BiMapInverseTester<K, V> extends AbstractBiMapTester<K, V> { 44  45  public void testInverseSame() { 46  assertSame(getMap(), getMap().inverse().inverse()); 47  } 48  49  @CollectionFeature.Require(SERIALIZABLE) 50  public void testInverseSerialization() { 51  BiMapPair<K, V> pair = new BiMapPair<>(getMap()); 52  BiMapPair<K, V> copy = SerializableTester.reserialize(pair); 53  assertEquals(pair.forward, copy.forward); 54  assertEquals(pair.backward, copy.backward); 55  assertSame(copy.backward, copy.forward.inverse()); 56  assertSame(copy.forward, copy.backward.inverse()); 57  } 58  59  private static class BiMapPair<K, V> implements Serializable { 60  final BiMap<K, V> forward; 61  final BiMap<V, K> backward; 62  63  BiMapPair(BiMap<K, V> original) { 64  this.forward = original; 65  this.backward = original.inverse(); 66  } 67  68  private static final long serialVersionUID = 0; 69  } 70  71  /** 72  * Returns {@link Method} instances for the tests that assume that the inverse will be the same 73  * after serialization. 74  */ 75  @GwtIncompatible // reflection 76  public static List<Method> getInverseSameAfterSerializingMethods() { 77  return Collections.singletonList(getMethod("testInverseSerialization")); 78  } 79  80  @GwtIncompatible // reflection 81  private static Method getMethod(String methodName) { 82  return Helpers.getMethod(BiMapInverseTester.class, methodName); 83  } 84 }