8 |
|
import static java.util.concurrent.TimeUnit.HOURS; |
9 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
|
|
11 |
+ |
import java.util.ArrayDeque; |
12 |
|
import java.util.ArrayList; |
13 |
|
import java.util.Arrays; |
14 |
|
import java.util.Collection; |
907 |
|
} |
908 |
|
} |
909 |
|
|
910 |
< |
public void testObjectMethods() { |
910 |
> |
public void testCollectionCopies() throws Exception { |
911 |
|
ThreadLocalRandom rnd = ThreadLocalRandom.current(); |
912 |
|
Collection c = impl.emptyCollection(); |
913 |
< |
for (int n = rnd.nextInt(3); n--> 0; ) |
913 |
> |
for (int n = rnd.nextInt(4); n--> 0; ) |
914 |
|
c.add(impl.makeElement(rnd.nextInt())); |
915 |
|
assertEquals(c, c); |
916 |
< |
if (c instanceof List) { |
917 |
< |
List copy = new ArrayList(c); |
918 |
< |
assertEquals(copy, c); |
919 |
< |
assertEquals(c, copy); |
920 |
< |
assertEquals(copy.hashCode(), c.hashCode()); |
921 |
< |
} |
922 |
< |
if (c instanceof Set) { |
923 |
< |
Set copy = new HashSet(c); |
924 |
< |
assertEquals(copy, c); |
925 |
< |
assertEquals(c, copy); |
926 |
< |
assertEquals(copy.hashCode(), c.hashCode()); |
916 |
> |
if (c instanceof List) |
917 |
> |
assertCollectionsEquals(c, new ArrayList(c)); |
918 |
> |
else if (c instanceof Set) |
919 |
> |
assertCollectionsEquals(c, new HashSet(c)); |
920 |
> |
else if (c instanceof Deque) |
921 |
> |
assertCollectionsEquivalent(c, new ArrayDeque(c)); |
922 |
> |
|
923 |
> |
Collection clone = cloneableClone(c); |
924 |
> |
if (clone != null) { |
925 |
> |
assertSame(c.getClass(), clone.getClass()); |
926 |
> |
assertCollectionsEquivalent(c, clone); |
927 |
|
} |
928 |
+ |
try { |
929 |
+ |
Collection serialClone = serialClonePossiblyFailing(c); |
930 |
+ |
assertSame(c.getClass(), serialClone.getClass()); |
931 |
+ |
assertCollectionsEquivalent(c, serialClone); |
932 |
+ |
} catch (java.io.NotSerializableException acceptable) {} |
933 |
|
} |
934 |
|
|
935 |
|
// public void testCollection8DebugFail() { |