001/*
002 * Copyright (C) 2013 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.collect.testing.google;
016
017import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
018
019import com.google.common.annotations.GwtCompatible;
020import com.google.common.collect.SortedSetMultimap;
021import com.google.common.collect.testing.features.MapFeature;
022import java.util.ArrayList;
023import java.util.Collection;
024import java.util.List;
025import java.util.SortedSet;
026
027/**
028 * Testers for {@link SortedSetMultimap#asMap}.
029 *
030 * @author Louis Wasserman
031 * @param <K> The key type of the tested multimap.
032 * @param <V> The value type of the tested multimap.
033 */
034@GwtCompatible
035public class SortedSetMultimapAsMapTester<K, V>
036    extends AbstractMultimapTester<K, V, SortedSetMultimap<K, V>> {
037  public void testAsMapValuesImplementSortedSet() {
038    for (Collection<V> valueCollection : multimap().asMap().values()) {
039      SortedSet<V> valueSet = (SortedSet<V>) valueCollection;
040      assertEquals(multimap().valueComparator(), valueSet.comparator());
041    }
042  }
043
044  public void testAsMapGetImplementsSortedSet() {
045    for (K key : multimap().keySet()) {
046      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key);
047      assertEquals(multimap().valueComparator(), valueSet.comparator());
048    }
049  }
050
051  @MapFeature.Require(SUPPORTS_REMOVE)
052  public void testAsMapRemoveImplementsSortedSet() {
053    List<K> keys = new ArrayList<>(multimap().keySet());
054    for (K key : keys) {
055      resetCollection();
056      SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().remove(key);
057      assertEquals(multimap().valueComparator(), valueSet.comparator());
058    }
059  }
060}