1 /* 2 * Copyright (C) 2009 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; 18 19 import static com.google.common.collect.Lists.newArrayList; 20 import static com.google.common.collect.testing.testers.CollectionAddAllTester.getAddAllUnsupportedNonePresentMethod; 21 import static com.google.common.collect.testing.testers.CollectionAddAllTester.getAddAllUnsupportedSomePresentMethod; 22 import static com.google.common.collect.testing.testers.CollectionAddTester.getAddUnsupportedNotPresentMethod; 23 import static com.google.common.collect.testing.testers.CollectionCreationTester.getCreateWithNullUnsupportedMethod; 24 import static com.google.common.collect.testing.testers.MapCreationTester.getCreateWithNullKeyUnsupportedMethod; 25 import static com.google.common.collect.testing.testers.MapEntrySetTester.getContainsEntryWithIncomparableKeyMethod; 26 import static com.google.common.collect.testing.testers.MapEntrySetTester.getContainsEntryWithIncomparableValueMethod; 27 import static com.google.common.collect.testing.testers.MapPutAllTester.getPutAllNullKeyUnsupportedMethod; 28 import static com.google.common.collect.testing.testers.MapPutTester.getPutNullKeyUnsupportedMethod; 29 30 import java.lang.reflect.Method; 31 import java.util.Arrays; 32 import java.util.Collection; 33 import java.util.List; 34 import java.util.Map; 35 import junit.framework.Test; 36 37 /** 38 * Tests the {@link Map} implementations of {@link java.util}, suppressing tests that trip known 39 * bugs in OpenJDK 6 or higher. 40 * 41 * @author Kevin Bourrillion 42 */ 43 /* 44 * TODO(cpovirk): consider renaming this class in light of our now running it 45 * under JDK7 46 */ 47 public class OpenJdk6MapTests extends TestsForMapsInJavaUtil { suite()48 public static Test suite() { 49 return new OpenJdk6MapTests().allTests(); 50 } 51 52 @Override suppressForTreeMapNatural()53 protected Collection<Method> suppressForTreeMapNatural() { 54 return Arrays.asList( 55 getPutNullKeyUnsupportedMethod(), 56 getPutAllNullKeyUnsupportedMethod(), 57 getCreateWithNullKeyUnsupportedMethod(), 58 getCreateWithNullUnsupportedMethod(), // for keySet 59 getContainsEntryWithIncomparableKeyMethod(), 60 getContainsEntryWithIncomparableValueMethod()); 61 } 62 63 @Override suppressForConcurrentHashMap()64 protected Collection<Method> suppressForConcurrentHashMap() { 65 /* 66 * The entrySet() of ConcurrentHashMap, unlike that of other Map 67 * implementations, supports add() under JDK8. This seems problematic, but I 68 * didn't see that discussed in the review, which included many other 69 * changes: http://goo.gl/okTTdr 70 * 71 * TODO(cpovirk): decide what the best long-term action here is: force users 72 * to suppress (as we do now), stop testing entrySet().add() at all, make 73 * entrySet().add() tests tolerant of either behavior, introduce a map 74 * feature for entrySet() that supports add(), or something else 75 */ 76 return Arrays.asList( 77 getAddUnsupportedNotPresentMethod(), 78 getAddAllUnsupportedNonePresentMethod(), 79 getAddAllUnsupportedSomePresentMethod()); 80 } 81 82 @Override suppressForConcurrentSkipListMap()83 protected Collection<Method> suppressForConcurrentSkipListMap() { 84 List<Method> methods = newArrayList(); 85 methods.addAll(super.suppressForConcurrentSkipListMap()); 86 methods.add(getContainsEntryWithIncomparableKeyMethod()); 87 methods.add(getContainsEntryWithIncomparableValueMethod()); 88 return methods; 89 } 90 } 91