test/jdk/java/util/List/ListFactories.java
author smarks
Thu, 21 Jun 2018 08:45:57 -0700
changeset 50698 c1f7ece09b84
parent 49283 a14ede52a278
child 50809 6ff774d73176
permissions -rw-r--r--
8203184: List.copyOf() fails to copy sublists Reviewed-by: psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
     1
/*
48059
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
     4
 *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
     8
 *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    13
 * accompanied this code).
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    14
 *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    18
 *
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    21
 * questions.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    22
 */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    23
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    24
import java.io.ByteArrayInputStream;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    25
import java.io.ByteArrayOutputStream;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    26
import java.io.IOException;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    27
import java.io.ObjectInputStream;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    28
import java.io.ObjectOutputStream;
49283
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
    29
import java.io.Serializable;
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    30
import java.util.ArrayList;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    31
import java.util.Arrays;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    32
import java.util.Collections;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    33
import java.util.Iterator;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    34
import java.util.List;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    35
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    36
import org.testng.annotations.DataProvider;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    37
import org.testng.annotations.Test;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    38
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    39
import static java.util.Arrays.asList;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    40
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    41
import static org.testng.Assert.assertEquals;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    42
import static org.testng.Assert.assertFalse;
48059
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
    43
import static org.testng.Assert.assertNotEquals;
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
    44
import static org.testng.Assert.assertNotSame;
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
    45
import static org.testng.Assert.assertSame;
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    46
import static org.testng.Assert.assertTrue;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    47
import static org.testng.Assert.fail;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    48
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    49
/*
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    50
 * @test
50698
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
    51
 * @bug 8048330 8203184
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    52
 * @summary Test convenience static factory methods on List.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    53
 * @run testng ListFactories
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    54
 */
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    55
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    56
public class ListFactories {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    57
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    58
    static final int NUM_STRINGS = 20; // should be larger than the largest fixed-arg overload
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    59
    static final String[] stringArray;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    60
    static {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    61
        String[] sa = new String[NUM_STRINGS];
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    62
        for (int i = 0; i < NUM_STRINGS; i++) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    63
            sa[i] = String.valueOf((char)('a' + i));
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    64
        }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    65
        stringArray = sa;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    66
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    67
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    68
    // returns array of [actual, expected]
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    69
    static Object[] a(List<String> act, List<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    70
        return new Object[] { act, exp };
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    71
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    72
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    73
    @DataProvider(name="empty")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    74
    public Iterator<Object[]> empty() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    75
        return Collections.singletonList(
49283
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
    76
            a(List.of(), asList())
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    77
        ).iterator();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    78
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    79
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    80
    @DataProvider(name="nonempty")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    81
    public Iterator<Object[]> nonempty() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    82
        return asList(
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    83
            a(List.of("a"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    84
               asList("a")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    85
            a(List.of("a", "b"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    86
               asList("a", "b")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    87
            a(List.of("a", "b", "c"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    88
               asList("a", "b", "c")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    89
            a(List.of("a", "b", "c", "d"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    90
               asList("a", "b", "c", "d")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    91
            a(List.of("a", "b", "c", "d", "e"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    92
               asList("a", "b", "c", "d", "e")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    93
            a(List.of("a", "b", "c", "d", "e", "f"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    94
               asList("a", "b", "c", "d", "e", "f")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    95
            a(List.of("a", "b", "c", "d", "e", "f", "g"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    96
               asList("a", "b", "c", "d", "e", "f", "g")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    97
            a(List.of("a", "b", "c", "d", "e", "f", "g", "h"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    98
               asList("a", "b", "c", "d", "e", "f", "g", "h")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    99
            a(List.of("a", "b", "c", "d", "e", "f", "g", "h", "i"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   100
               asList("a", "b", "c", "d", "e", "f", "g", "h", "i")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   101
            a(List.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   102
               asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   103
            a(List.of(stringArray),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   104
               asList(stringArray))
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   105
        ).iterator();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   106
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   107
49283
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   108
    @DataProvider(name="sublists")
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   109
    public Iterator<Object[]> sublists() {
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   110
        return asList(
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   111
            a(List.<String>of().subList(0,0),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   112
               asList()),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   113
            a(List.of("a").subList(0,0),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   114
               asList("a").subList(0,0)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   115
            a(List.of("a", "b").subList(0,1),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   116
               asList("a", "b").subList(0,1)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   117
            a(List.of("a", "b", "c").subList(1,3),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   118
               asList("a", "b", "c").subList(1,3)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   119
            a(List.of("a", "b", "c", "d").subList(0,4),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   120
               asList("a", "b", "c", "d").subList(0,4)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   121
            a(List.of("a", "b", "c", "d", "e").subList(0,3),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   122
               asList("a", "b", "c", "d", "e").subList(0,3)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   123
            a(List.of("a", "b", "c", "d", "e", "f").subList(3, 5),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   124
               asList("a", "b", "c", "d", "e", "f").subList(3, 5)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   125
            a(List.of("a", "b", "c", "d", "e", "f", "g").subList(0, 7),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   126
               asList("a", "b", "c", "d", "e", "f", "g").subList(0, 7)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   127
            a(List.of("a", "b", "c", "d", "e", "f", "g", "h").subList(0, 0),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   128
               asList("a", "b", "c", "d", "e", "f", "g", "h").subList(0, 0)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   129
            a(List.of("a", "b", "c", "d", "e", "f", "g", "h", "i").subList(4, 5),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   130
               asList("a", "b", "c", "d", "e", "f", "g", "h", "i").subList(4, 5)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   131
            a(List.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j").subList(1,10),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   132
               asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j").subList(1,10)),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   133
            a(List.of(stringArray).subList(5, NUM_STRINGS),
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   134
               asList(Arrays.copyOfRange(stringArray, 5, NUM_STRINGS)))
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   135
                ).iterator();
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   136
    }
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   137
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   138
    @DataProvider(name="all")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   139
    public Iterator<Object[]> all() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   140
        List<Object[]> all = new ArrayList<>();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   141
        empty().forEachRemaining(all::add);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   142
        nonempty().forEachRemaining(all::add);
49283
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   143
        sublists().forEachRemaining(all::add);
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   144
        return all.iterator();
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   145
    }
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   146
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   147
    @DataProvider(name="nonsublists")
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   148
    public Iterator<Object[]> nonsublists() {
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   149
        List<Object[]> all = new ArrayList<>();
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   150
        empty().forEachRemaining(all::add);
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   151
        nonempty().forEachRemaining(all::add);
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   152
        return all.iterator();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   153
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   154
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   155
    @Test(dataProvider="all", expectedExceptions=UnsupportedOperationException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   156
    public void cannotAddLast(List<String> act, List<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   157
        act.add("x");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   158
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   159
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   160
    @Test(dataProvider="all", expectedExceptions=UnsupportedOperationException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   161
    public void cannotAddFirst(List<String> act, List<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   162
        act.add(0, "x");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   163
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   164
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   165
    @Test(dataProvider="nonempty", expectedExceptions=UnsupportedOperationException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   166
    public void cannotRemove(List<String> act, List<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   167
        act.remove(0);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   168
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   169
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   170
    @Test(dataProvider="nonempty", expectedExceptions=UnsupportedOperationException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   171
    public void cannotSet(List<String> act, List<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   172
        act.set(0, "x");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   173
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   174
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   175
    @Test(dataProvider="all")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   176
    public void contentsMatch(List<String> act, List<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   177
        assertEquals(act, exp);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   178
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   179
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   180
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   181
    public void nullDisallowed1() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   182
        List.of((Object)null); // force one-arg overload
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   183
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   184
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   185
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   186
    public void nullDisallowed2a() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   187
        List.of("a", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   188
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   189
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   190
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   191
    public void nullDisallowed2b() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   192
        List.of(null, "b");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   193
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   194
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   195
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   196
    public void nullDisallowed3() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   197
        List.of("a", "b", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   198
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   199
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   200
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   201
    public void nullDisallowed4() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   202
        List.of("a", "b", "c", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   203
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   204
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   205
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   206
    public void nullDisallowed5() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   207
        List.of("a", "b", "c", "d", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   208
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   209
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   210
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   211
    public void nullDisallowed6() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   212
        List.of("a", "b", "c", "d", "e", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   213
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   214
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   215
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   216
    public void nullDisallowed7() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   217
        List.of("a", "b", "c", "d", "e", "f", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   218
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   219
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   220
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   221
    public void nullDisallowed8() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   222
        List.of("a", "b", "c", "d", "e", "f", "g", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   223
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   224
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   225
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   226
    public void nullDisallowed9() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   227
        List.of("a", "b", "c", "d", "e", "f", "g", "h", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   228
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   229
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   230
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   231
    public void nullDisallowed10() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   232
        List.of("a", "b", "c", "d", "e", "f", "g", "h", "i", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   233
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   234
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   235
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   236
    public void nullDisallowedN() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   237
        String[] array = stringArray.clone();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   238
        array[0] = null;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   239
        List.of(array);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   240
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   241
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   242
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   243
    public void nullArrayDisallowed() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   244
        List.of((Object[])null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   245
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   246
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   247
    @Test
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   248
    public void ensureArrayCannotModifyList() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   249
        String[] array = stringArray.clone();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   250
        List<String> list = List.of(array);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   251
        array[0] = "xyzzy";
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   252
        assertEquals(list, Arrays.asList(stringArray));
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   253
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   254
49283
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   255
    @Test(dataProvider="all", expectedExceptions=NullPointerException.class)
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   256
    public void containsNullShouldThrowNPE(List<String> act, List<String> exp) {
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   257
        act.contains(null);
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   258
    }
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   259
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   260
    @Test(dataProvider="all", expectedExceptions=NullPointerException.class)
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   261
    public void indexOfNullShouldThrowNPE(List<String> act, List<String> exp) {
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   262
        act.indexOf(null);
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   263
    }
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   264
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   265
    @Test(dataProvider="all", expectedExceptions=NullPointerException.class)
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   266
    public void lastIndexOfNullShouldThrowNPE(List<String> act, List<String> exp) {
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   267
        act.lastIndexOf(null);
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   268
    }
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   269
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   270
    // List.of().subList views should not be Serializable
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   271
    @Test(dataProvider="sublists")
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   272
    public void isNotSerializable(List<String> act, List<String> exp) {
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   273
        assertFalse(act instanceof Serializable);
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   274
    }
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   275
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   276
    // ... but List.of() should be
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   277
    @Test(dataProvider="nonsublists")
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   278
    public void serialEquality(List<String> act, List<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   279
        // assume that act.equals(exp) tested elsewhere
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   280
        List<String> copy = serialClone(act);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   281
        assertEquals(act, copy);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   282
        assertEquals(copy, exp);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   283
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   284
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   285
    @SuppressWarnings("unchecked")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   286
    static <T> T serialClone(T obj) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   287
        try {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   288
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
48059
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   289
            try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   290
                oos.writeObject(obj);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   291
            }
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   292
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   293
            ObjectInputStream ois = new ObjectInputStream(bais);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   294
            return (T) ois.readObject();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   295
        } catch (IOException | ClassNotFoundException e) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   296
            throw new AssertionError(e);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   297
        }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   298
    }
48059
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   299
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   300
    List<Integer> genList() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   301
        return new ArrayList<>(Arrays.asList(1, 2, 3));
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   302
    }
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   303
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   304
    @Test
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   305
    public void copyOfResultsEqual() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   306
        List<Integer> orig = genList();
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   307
        List<Integer> copy = List.copyOf(orig);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   308
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   309
        assertEquals(orig, copy);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   310
        assertEquals(copy, orig);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   311
    }
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   312
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   313
    @Test
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   314
    public void copyOfModifiedUnequal() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   315
        List<Integer> orig = genList();
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   316
        List<Integer> copy = List.copyOf(orig);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   317
        orig.add(4);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   318
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   319
        assertNotEquals(orig, copy);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   320
        assertNotEquals(copy, orig);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   321
    }
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   322
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   323
    @Test
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   324
    public void copyOfIdentity() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   325
        List<Integer> orig = genList();
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   326
        List<Integer> copy1 = List.copyOf(orig);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   327
        List<Integer> copy2 = List.copyOf(copy1);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   328
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   329
        assertNotSame(orig, copy1);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   330
        assertSame(copy1, copy2);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   331
    }
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   332
50698
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   333
    @Test
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   334
    public void copyOfSubList() {
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   335
        List<Integer> orig = List.of(0, 1, 2, 3);
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   336
        List<Integer> sub = orig.subList(0, 3);
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   337
        List<Integer> copy = List.copyOf(sub);
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   338
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   339
        assertNotSame(sub, copy);
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   340
    }
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   341
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   342
    @Test
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   343
    public void copyOfSubSubList() {
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   344
        List<Integer> orig = List.of(0, 1, 2, 3);
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   345
        List<Integer> sub = orig.subList(0, 3).subList(0, 2);
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   346
        List<Integer> copy = List.copyOf(sub);
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   347
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   348
        assertNotSame(sub, copy);
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   349
    }
c1f7ece09b84 8203184: List.copyOf() fails to copy sublists
smarks
parents: 49283
diff changeset
   350
48059
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   351
    @Test(expectedExceptions=NullPointerException.class)
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   352
    public void copyOfRejectsNullCollection() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   353
        List<Integer> list = List.copyOf(null);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   354
    }
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   355
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   356
    @Test(expectedExceptions=NullPointerException.class)
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   357
    public void copyOfRejectsNullElements() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   358
        List<Integer> list = List.copyOf(Arrays.asList(1, null, 3));
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   359
    }
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   360
}