Home | History | Annotate | Download | only in collect
      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;
     18 
     19 import static com.google.common.truth.Truth.assertThat;
     20 
     21 import com.google.common.annotations.GwtCompatible;
     22 import com.google.common.collect.testing.AnEnum;
     23 import com.google.common.collect.testing.Helpers;
     24 import com.google.common.collect.testing.TestEnumMapGenerator;
     25 
     26 import junit.framework.TestCase;
     27 
     28 import java.util.Map;
     29 import java.util.Map.Entry;
     30 
     31 /**
     32  * Tests for {@code ImmutableEnumMap}.
     33  *
     34  * @author Louis Wasserman
     35  */
     36 @GwtCompatible(emulated = true)
     37 public class ImmutableEnumMapTest extends TestCase {
     38   public static class ImmutableEnumMapGenerator extends TestEnumMapGenerator {
     39     @Override
     40     protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
     41       Map<AnEnum, String> map = Maps.newHashMap();
     42       for (Entry<AnEnum, String> entry : entries) {
     43         map.put(entry.getKey(), entry.getValue());
     44       }
     45       return Maps.immutableEnumMap(map);
     46     }
     47   }
     48 
     49   public void testEmptyImmutableEnumMap() {
     50     ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(ImmutableMap.<AnEnum, String>of());
     51     assertEquals(ImmutableMap.of(), map);
     52   }
     53 
     54   public void testImmutableEnumMapOrdering() {
     55     ImmutableMap<AnEnum, String> map = Maps.immutableEnumMap(
     56         ImmutableMap.of(AnEnum.C, "c", AnEnum.A, "a", AnEnum.E, "e"));
     57 
     58     assertThat(map.entrySet()).has().exactly(
     59         Helpers.mapEntry(AnEnum.A, "a"),
     60         Helpers.mapEntry(AnEnum.C, "c"),
     61         Helpers.mapEntry(AnEnum.E, "e")).inOrder();
     62   }
     63 }
     64 
     65