Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.google.common.collect.testing;
 
 
 
 import java.util.Map;
Generates a test suite covering the java.util.Map implementations in the java.util package. Can be subclassed to specify tests that should be suppressed.

Author(s):
Kevin Bourrillion
 
 public class TestsForMapsInJavaUtil {
 
   public static Test suite() {
     return new TestsForMapsInJavaUtil().allTests();
   }
 
   public Test allTests() {
     TestSuite suite = new TestSuite("java.util Maps");
     suite.addTest(testsForEmptyMap());
     suite.addTest(testsForSingletonMap());
     suite.addTest(testsForHashMap());
     suite.addTest(testsForLinkedHashMap());
     suite.addTest(testsForEnumMap());
     return suite;
   }
 
   protected Collection<MethodsuppressForEmptyMap() {
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
   protected Collection<MethodsuppressForHashMap() {
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
   protected Collection<MethodsuppressForEnumMap() {
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
     return Collections.emptySet();
   }
 
   public Test testsForEmptyMap() {
     return MapTestSuiteBuilder
         .using(new TestStringMapGenerator() {
             @Override protected Map<StringStringcreate(
                 Entry<StringString>[] entries) {
               return Collections.emptyMap();
             }
           })
         .named("emptyMap")
         .withFeatures(
            .,
            .)
        .createTestSuite();
  }
  public Test testsForSingletonMap() {
    return MapTestSuiteBuilder
        .using(new TestStringMapGenerator() {
            @Override protected Map<StringStringcreate(
                Entry<StringString>[] entries) {
              return Collections.singletonMap(
                  entries[0].getKey(), entries[0].getValue());
            }
          })
        .named("singletonMap")
        .withFeatures(
            .,
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
  public Test testsForHashMap() {
    return MapTestSuiteBuilder
        .using(new TestStringMapGenerator() {
            @Override protected Map<StringStringcreate(
                Entry<StringString>[] entries) {
              return toHashMap(entries);
            }
          })
        .named("HashMap")
        .withFeatures(
            .,
            .,
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
  public Test testsForLinkedHashMap() {
    return MapTestSuiteBuilder
        .using(new TestStringMapGenerator() {
            @Override protected Map<StringStringcreate(
                Entry<StringString>[] entries) {
              return populate(new LinkedHashMap<StringString>(), entries);
            }
          })
        .named("LinkedHashMap")
        .withFeatures(
            .,
            .,
            .,
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
  public Test testsForEnumMap() {
    return MapTestSuiteBuilder
        .using(new TestEnumMapGenerator() {
            @Override protected Map<AnEnumStringcreate(
                Entry<AnEnumString>[] entries) {
              return populate(
                  new EnumMap<AnEnumString>(AnEnum.class), entries);
            }
          })
        .named("EnumMap")
        .withFeatures(
            .,
            .,
            .,
            .,
            .,
            .)
        .createTestSuite();
  }
    return MapTestSuiteBuilder
        .using(new TestStringMapGenerator() {
          @Override protected Map<StringStringcreate(
              Entry<StringString>[] entries) {
            return populate(new ConcurrentHashMap<StringString>(), entries);
          }
        })
        .named("ConcurrentHashMap")
        .withFeatures(
            .,
            .,
            .)
        .createTestSuite();
  }
  // TODO: IdentityHashMap, AbstractMap
  private static Map<StringStringtoHashMap(
      Entry<StringString>[] entries) {
    return populate(new HashMap<StringString>(), entries);
  }
  // TODO: call conversion constructors or factory methods instead of using
  // populate() on an empty map
  private static <T, M extends Map<T, String>> M populate(
      M mapEntry<T, String>[] entries) {
    for (Entry<T, Stringentry : entries) {
      map.put(entry.getKey(), entry.getValue());
    }
    return map;
  }
    return new NullFriendlyComparator<T>();
  }
  private static final class NullFriendlyComparator<T> implements Comparator<T>, Serializable {
    @Override
    public int compare(T left, T right) {
      return String.valueOf(left).compareTo(String.valueOf(right));
    }
  }
New to GrepCode? Check out our FAQ X