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

Class Class, % Method, % Line, %
BiMapPutTester 0% (0/1) 0% (0/10) 0% (0/59)


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.CollectionSize.ONE; 20 import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 21 import static com.google.common.collect.testing.features.CollectionSize.ZERO; 22 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS; 23 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES; 24 import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; 25  26 import com.google.common.annotations.GwtCompatible; 27 import com.google.common.collect.testing.Helpers; 28 import com.google.common.collect.testing.features.CollectionSize; 29 import com.google.common.collect.testing.features.MapFeature; 30 import org.junit.Ignore; 31  32 /** Tester for {@code BiMap.put} and {@code BiMap.forcePut}. */ 33 @GwtCompatible 34 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 35 public class BiMapPutTester<K, V> extends AbstractBiMapTester<K, V> { 36  37  @SuppressWarnings("unchecked") 38  @MapFeature.Require(SUPPORTS_PUT) 39  @CollectionSize.Require(ZERO) 40  public void testPutWithSameValueFails() { 41  getMap().put(k0(), v0()); 42  try { 43  getMap().put(k1(), v0()); 44  fail("Expected IllegalArgumentException"); 45  } catch (IllegalArgumentException expected) { 46  // success 47  } 48  // verify that the bimap is unchanged 49  expectAdded(e0()); 50  } 51  52  @SuppressWarnings("unchecked") 53  @MapFeature.Require(SUPPORTS_PUT) 54  @CollectionSize.Require(ZERO) 55  public void testPutPresentKeyDifferentValue() { 56  getMap().put(k0(), v0()); 57  getMap().put(k0(), v1()); 58  // verify that the bimap is changed, and that the old inverse mapping 59  // from v1 -> v0 is deleted 60  expectContents(Helpers.mapEntry(k0(), v1())); 61  } 62  63  @SuppressWarnings("unchecked") 64  @MapFeature.Require(SUPPORTS_PUT) 65  @CollectionSize.Require(ZERO) 66  public void putDistinctKeysDistinctValues() { 67  getMap().put(k0(), v0()); 68  getMap().put(k1(), v1()); 69  expectAdded(e0(), e1()); 70  } 71  72  @SuppressWarnings("unchecked") 73  @MapFeature.Require(SUPPORTS_PUT) 74  @CollectionSize.Require(ONE) 75  public void testForcePutKeyPresent() { 76  getMap().forcePut(k0(), v1()); 77  expectContents(Helpers.mapEntry(k0(), v1())); 78  assertFalse(getMap().containsValue(v0())); 79  assertNull(getMap().inverse().get(v0())); 80  assertEquals(1, getMap().size()); 81  assertTrue(getMap().containsKey(k0())); 82  } 83  84  @SuppressWarnings("unchecked") 85  @MapFeature.Require(SUPPORTS_PUT) 86  @CollectionSize.Require(ONE) 87  public void testForcePutValuePresent() { 88  getMap().forcePut(k1(), v0()); 89  expectContents(Helpers.mapEntry(k1(), v0())); 90  assertEquals(k1(), getMap().inverse().get(v0())); 91  assertEquals(1, getMap().size()); 92  assertFalse(getMap().containsKey(k0())); 93  } 94  95  @SuppressWarnings("unchecked") 96  @MapFeature.Require(SUPPORTS_PUT) 97  @CollectionSize.Require(SEVERAL) 98  public void testForcePutKeyAndValuePresent() { 99  getMap().forcePut(k0(), v1()); 100  expectContents(Helpers.mapEntry(k0(), v1()), Helpers.mapEntry(k2(), v2())); 101  assertEquals(2, getMap().size()); 102  assertFalse(getMap().containsKey(k1())); 103  assertFalse(getMap().containsValue(v0())); 104  } 105  106  @SuppressWarnings("unchecked") 107  @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS}) 108  @CollectionSize.Require(ONE) 109  public void testForcePutNullKeyPresent() { 110  initMapWithNullKey(); 111  112  getMap().forcePut(null, v1()); 113  114  expectContents(Helpers.mapEntry((K) null, v1())); 115  116  assertFalse(getMap().containsValue(v0())); 117  118  assertTrue(getMap().containsValue(v1())); 119  assertTrue(getMap().inverse().containsKey(v1())); 120  assertNull(getMap().inverse().get(v1())); 121  assertEquals(v1(), getMap().get(null)); 122  assertEquals(1, getMap().size()); 123  } 124  125  @SuppressWarnings("unchecked") 126  @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) 127  @CollectionSize.Require(ONE) 128  public void testForcePutNullValuePresent() { 129  initMapWithNullValue(); 130  131  getMap().forcePut(k1(), null); 132  133  expectContents(Helpers.mapEntry(k1(), (V) null)); 134  135  assertFalse(getMap().containsKey(k0())); 136  137  assertTrue(getMap().containsKey(k1())); 138  assertTrue(getMap().inverse().containsKey(null)); 139  assertNull(getMap().get(k1())); 140  assertEquals(k1(), getMap().inverse().get(null)); 141  assertEquals(1, getMap().size()); 142  } 143  144  // nb: inverse is run through its own entire suite 145  146  @SuppressWarnings("unchecked") 147  @MapFeature.Require(SUPPORTS_PUT) 148  @CollectionSize.Require(ZERO) 149  public void testInversePut() { 150  getMap().put(k0(), v0()); 151  getMap().inverse().put(v1(), k1()); 152  expectAdded(e0(), e1()); 153  } 154 }