--- old/test/java/util/Collections/EmptyCollectionSerialization.java 2013-06-07 09:53:20.882587775 -0700 +++ new/test/java/util/Collections/EmptyCollectionSerialization.java 2013-06-07 09:53:20.658587764 -0700 @@ -23,13 +23,20 @@ /* * @test - * @bug 4684279 + * @bug 4684279 7129185 * @summary Empty utility collections should be singletons * @author Josh Bloch + * @run testng EmptyCollectionSerialization */ import java.util.*; +import java.util.function.Supplier; import java.io.*; +import org.testng.annotations.Test; +import org.testng.annotations.DataProvider; + +import static org.testng.Assert.fail; +import static org.testng.Assert.assertSame; public class EmptyCollectionSerialization { private static Object patheticDeepCopy(Object o) throws Exception { @@ -45,16 +52,42 @@ return ois.readObject(); } - private static boolean isSingleton(Object o) throws Exception { - return patheticDeepCopy(o) == o; + @Test(dataProvider="SerializableSingletons") + public static void serializableSingletons(String description, Supplier o) { + try { + assertSame(patheticDeepCopy(o.get()), o.get(), description + ": not a singleton"); + } catch(Exception all) { + fail(description + ": Unexpected Exception", all); + } + } + + @DataProvider(name = "SerializableSingletons", parallel = true) + public static Iterator navigableMapProvider() { + return makeSingletons().iterator(); } - public static void main(String[] args) throws Exception { - if (!isSingleton(Collections.EMPTY_SET)) - throw new Exception("EMPTY_SET"); - if (!isSingleton(Collections.EMPTY_LIST)) - throw new Exception("EMPTY_LIST"); - if (!isSingleton(Collections.EMPTY_MAP)) - throw new Exception("EMPTY_MAP"); + public static Collection makeSingletons() { + return Arrays.asList( + new Object[]{"Collections.EMPTY_LIST", + (Supplier) () -> {return Collections.EMPTY_LIST;}}, + new Object[]{"Collections.EMPTY_MAP", + (Supplier) () -> {return Collections.EMPTY_MAP;}}, + new Object[]{"Collections.EMPTY_SET", + (Supplier) () -> {return Collections.EMPTY_SET;}}, + new Object[]{"Collections.singletonMap()", + (Supplier) () -> {return Collections.emptyList();}}, + new Object[]{"Collections.emptyMap()", + (Supplier) () -> {return Collections.emptyMap();}}, + new Object[]{"Collections.emptySet()", + (Supplier) () -> {return Collections.emptySet();}}, + new Object[]{"Collections.emptySortedSet()", + (Supplier) () -> {return Collections.emptySortedSet();}}, + new Object[]{"Collections.emptySortedMap()", + (Supplier) () -> {return Collections.emptySortedMap();}}, + new Object[]{"Collections.emptyNavigableSet()", + (Supplier) () -> {return Collections.emptyNavigableSet();}}, + new Object[]{"Collections.emptyNavigableMap()", + (Supplier) () -> {return Collections.emptyNavigableMap();}} + ); } }