< prev index next >
test/jdk/java/util/Collection/MOAT.java
Print this page
rev 48060 : 8060192: Add default method <A> A[] Collection.toArray(IntFunction<A[]> generator)
Reviewed-by: XXX
*** 361,370 ****
--- 361,371 ----
check(c.isEmpty());
equal(c.size(), 0);
equal(c.toString(),"[]");
equal(c.toArray().length, 0);
equal(c.toArray(new Object[0]).length, 0);
+ equal(c.toArray(Object[]::new).length, 0);
check(c.toArray(new Object[]{42})[0] == null);
Object[] a = new Object[1]; a[0] = Boolean.TRUE;
equal(c.toArray(a), a);
equal(a[0], null);
*** 600,615 ****
catch (UnsupportedOperationException t) { return false; }
catch (Throwable t) { unexpected(t); }
return true;
}
- // 6260652: (coll) Arrays.asList(x).toArray().getClass()
- // should be Object[].class
- // Fixed in jdk9, but not jdk8 ...
- static final boolean needToWorkAround6260652 =
- Arrays.asList("").toArray().getClass() != Object[].class;
-
private static void checkFunctionalInvariants(Collection<Integer> c) {
try {
checkContainsSelf(c);
checkContainsEmpty(c);
check(c.size() != 0 ^ c.isEmpty());
--- 601,610 ----
*** 624,645 ****
if (c instanceof Set) {
checkUnique((Set<Integer>)c);
}
check(c.toArray().length == c.size());
! check(c.toArray().getClass() == Object[].class
! ||
! (needToWorkAround6260652 &&
! c.getClass().getName().equals("java.util.Arrays$ArrayList")));
for (int size : new int[]{0,1,c.size(), c.size()+1}) {
Integer[] a = c.toArray(new Integer[size]);
check((size > c.size()) || a.length == c.size());
int i = 0; for (Integer j : c) check(a[i++] == j);
check((size <= c.size()) || (a[c.size()] == null));
check(a.getClass() == Integer[].class);
}
check(c.equals(c));
if (c instanceof Serializable) {
//System.out.printf("Serializing %s%n", c.getClass().getName());
try {
Object clone = serialClone(c);
--- 619,644 ----
if (c instanceof Set) {
checkUnique((Set<Integer>)c);
}
check(c.toArray().length == c.size());
! check(c.toArray().getClass() == Object[].class);
for (int size : new int[]{0,1,c.size(), c.size()+1}) {
Integer[] a = c.toArray(new Integer[size]);
check((size > c.size()) || a.length == c.size());
int i = 0; for (Integer j : c) check(a[i++] == j);
check((size <= c.size()) || (a[c.size()] == null));
check(a.getClass() == Integer[].class);
}
+ {
+ Integer[] a = c.toArray(Integer[]::new);
+ equal(c.size(), a.length);
+ check(a.getClass() == Integer[].class);
+ check(Arrays.equals(c.toArray(new Integer[0]), a));
+ }
+
check(c.equals(c));
if (c instanceof Serializable) {
//System.out.printf("Serializing %s%n", c.getClass().getName());
try {
Object clone = serialClone(c);
< prev index next >