001/* 002 * Copyright (C) 2017 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.collect.testing.google; 018 019import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 020import static com.google.common.collect.testing.features.CollectionSize.ZERO; 021import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES; 022import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; 023 024import com.google.common.annotations.GwtCompatible; 025import com.google.common.collect.testing.features.CollectionSize; 026import com.google.common.collect.testing.features.MapFeature; 027import java.util.Map.Entry; 028import org.junit.Ignore; 029 030/** Tester for {@code BiMap.entrySet} and methods on the entries in the set. */ 031@GwtCompatible 032@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 033public class BiMapEntrySetTester<K, V> extends AbstractBiMapTester<K, V> { 034 @MapFeature.Require(SUPPORTS_PUT) 035 @CollectionSize.Require(absent = ZERO) 036 public void testSetValue_valueAbsent() { 037 for (Entry<K, V> entry : getMap().entrySet()) { 038 if (entry.getKey().equals(k0())) { 039 assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3())); 040 } 041 } 042 expectReplacement(entry(k0(), v3())); 043 } 044 045 @MapFeature.Require(SUPPORTS_PUT) 046 @CollectionSize.Require(SEVERAL) 047 public void testSetValue_valuePresent() { 048 for (Entry<K, V> entry : getMap().entrySet()) { 049 if (entry.getKey().equals(k0())) { 050 try { 051 entry.setValue(v1()); 052 fail("Expected IllegalArgumentException"); 053 } catch (IllegalArgumentException expected) { 054 } 055 } 056 } 057 expectUnchanged(); 058 } 059 060 @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) 061 @CollectionSize.Require(absent = ZERO) 062 public void testSetValueNullUnsupported() { 063 for (Entry<K, V> entry : getMap().entrySet()) { 064 try { 065 entry.setValue(null); 066 fail("Expected NullPointerException"); 067 } catch (NullPointerException expected) { 068 } 069 expectUnchanged(); 070 } 071 } 072 073 @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) 074 @CollectionSize.Require(absent = ZERO) 075 public void testSetValueNullSupported() { 076 for (Entry<K, V> entry : getMap().entrySet()) { 077 if (entry.getKey().equals(k0())) { 078 entry.setValue(null); 079 } 080 } 081 expectReplacement(entry(k0(), (V) null)); 082 } 083}