test/jdk/java/util/Collection/SetFactories.java
author pli
Tue, 16 Jul 2019 00:57:00 +0000
changeset 55689 8c5c9d86e1d6
parent 49283 a14ede52a278
permissions -rw-r--r--
8227512: [TESTBUG] Fix JTReg javac test failures with Graal Reviewed-by: mcimadamore
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
/*
43068
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
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;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    29
import java.util.ArrayList;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    30
import java.util.Arrays;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    31
import java.util.Collections;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    32
import java.util.Iterator;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    33
import java.util.HashSet;
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
import java.util.Set;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    36
import java.util.stream.Collectors;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    37
import static org.testng.Assert.assertEquals;
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 org.testng.annotations.DataProvider;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    40
import org.testng.annotations.Test;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    41
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
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    51
 * @bug 8048330
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    52
 * @summary Test convenience static factory methods on Set.
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    53
 * @run testng SetFactories
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
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    57
public class SetFactories {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    58
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    59
    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
    60
    static final String[] stringArray;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    61
    static {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    62
        String[] sa = new String[NUM_STRINGS];
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    63
        for (int i = 0; i < NUM_STRINGS; i++) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    64
            sa[i] = String.valueOf((char)('a' + i));
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    65
        }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    66
        stringArray = sa;
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
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    69
    static Object[] a(Set<String> act, Set<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
    static Set<String> hashSetOf(String... args) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    74
        return new HashSet<>(Arrays.asList(args));
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    75
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    76
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    77
    @DataProvider(name="empty")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    78
    public Iterator<Object[]> empty() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    79
        return Collections.singletonList(
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    80
            // actual, expected
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    81
            a(Set.of(), Collections.emptySet())
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    82
        ).iterator();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    83
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    84
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    85
    @DataProvider(name="nonempty")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    86
    public Iterator<Object[]> nonempty() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    87
        return Arrays.asList(
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    88
            // actual, expected
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    89
            a(   Set.of("a"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    90
              hashSetOf("a")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    91
            a(   Set.of("a", "b"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    92
              hashSetOf("a", "b")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    93
            a(   Set.of("a", "b", "c"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    94
              hashSetOf("a", "b", "c")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    95
            a(   Set.of("a", "b", "c", "d"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    96
              hashSetOf("a", "b", "c", "d")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    97
            a(   Set.of("a", "b", "c", "d", "e"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    98
              hashSetOf("a", "b", "c", "d", "e")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
    99
            a(   Set.of("a", "b", "c", "d", "e", "f"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   100
              hashSetOf("a", "b", "c", "d", "e", "f")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   101
            a(   Set.of("a", "b", "c", "d", "e", "f", "g"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   102
              hashSetOf("a", "b", "c", "d", "e", "f", "g")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   103
            a(   Set.of("a", "b", "c", "d", "e", "f", "g", "h"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   104
              hashSetOf("a", "b", "c", "d", "e", "f", "g", "h")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   105
            a(   Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   106
              hashSetOf("a", "b", "c", "d", "e", "f", "g", "h", "i")),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   107
            a(   Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   108
              hashSetOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")),
43068
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   109
            a(   Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   110
                 Set.of("j", "i", "h", "g", "f", "e", "d", "c", "b", "a")),
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   111
            a(   Set.of(stringArray),
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   112
              hashSetOf(stringArray))
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   113
        ).iterator();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   114
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   115
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   116
    @DataProvider(name="all")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   117
    public Iterator<Object[]> all() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   118
        List<Object[]> all = new ArrayList<>();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   119
        empty().forEachRemaining(all::add);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   120
        nonempty().forEachRemaining(all::add);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   121
        return all.iterator();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   122
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   123
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   124
    @Test(dataProvider="all", expectedExceptions=UnsupportedOperationException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   125
    public void cannotAdd(Set<String> act, Set<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   126
        act.add("x");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   127
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   128
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   129
    @Test(dataProvider="nonempty", expectedExceptions=UnsupportedOperationException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   130
    public void cannotRemove(Set<String> act, Set<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   131
        act.remove(act.iterator().next());
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   132
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   133
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   134
    @Test(dataProvider="all")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   135
    public void contentsMatch(Set<String> act, Set<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   136
        assertEquals(act, exp);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   137
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   138
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   139
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   140
    public void dupsDisallowed2() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   141
        Set<String> set = Set.of("a", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   142
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   143
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   144
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   145
    public void dupsDisallowed3() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   146
        Set<String> set = Set.of("a", "b", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   147
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   148
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   149
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   150
    public void dupsDisallowed4() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   151
        Set<String> set = Set.of("a", "b", "c", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   152
    }
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
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   155
    public void dupsDisallowed5() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   156
        Set<String> set = Set.of("a", "b", "c", "d", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   157
    }
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
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   160
    public void dupsDisallowed6() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   161
        Set<String> set = Set.of("a", "b", "c", "d", "e", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   162
    }
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
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   165
    public void dupsDisallowed7() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   166
        Set<String> set = Set.of("a", "b", "c", "d", "e", "f", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   167
    }
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
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   170
    public void dupsDisallowed8() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   171
        Set<String> set = Set.of("a", "b", "c", "d", "e", "f", "g", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   172
    }
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
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   175
    public void dupsDisallowed9() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   176
        Set<String> set = Set.of("a", "b", "c", "d", "e", "f", "g", "h", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   177
    }
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
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   180
    public void dupsDisallowed10() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   181
        Set<String> set = Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", "a");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   182
    }
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
    @Test(expectedExceptions=IllegalArgumentException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   185
    public void dupsDisallowedN() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   186
        String[] array = stringArray.clone();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   187
        array[0] = array[1];
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   188
        Set<String> set = Set.of(array);
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
43068
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   191
    @Test(dataProvider="all")
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   192
    public void hashCodeEqual(Set<String> act, Set<String> exp) {
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   193
        assertEquals(act.hashCode(), exp.hashCode());
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   194
    }
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   195
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   196
    @Test(dataProvider="all")
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   197
    public void containsAll(Set<String> act, Set<String> exp) {
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   198
        assertTrue(act.containsAll(exp));
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   199
        assertTrue(exp.containsAll(act));
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   200
    }
df01087b2c43 8166365: Small immutable collections should provide optimized implementations when possible
redestad
parents: 34527
diff changeset
   201
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   202
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   203
    public void nullDisallowed1() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   204
        Set.of((String)null); // force one-arg overload
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   205
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   206
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   207
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   208
    public void nullDisallowed2a() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   209
        Set.of("a", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   210
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   211
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   212
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   213
    public void nullDisallowed2b() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   214
        Set.of(null, "b");
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   215
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   216
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   217
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   218
    public void nullDisallowed3() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   219
        Set.of("a", "b", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   220
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   221
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   222
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   223
    public void nullDisallowed4() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   224
        Set.of("a", "b", "c", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   225
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   226
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   227
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   228
    public void nullDisallowed5() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   229
        Set.of("a", "b", "c", "d", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   230
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   231
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   232
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   233
    public void nullDisallowed6() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   234
        Set.of("a", "b", "c", "d", "e", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   235
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   236
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   237
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   238
    public void nullDisallowed7() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   239
        Set.of("a", "b", "c", "d", "e", "f", null);
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 nullDisallowed8() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   244
        Set.of("a", "b", "c", "d", "e", "f", "g", 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(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   248
    public void nullDisallowed9() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   249
        Set.of("a", "b", "c", "d", "e", "f", "g", "h", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   250
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   251
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   252
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   253
    public void nullDisallowed10() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   254
        Set.of("a", "b", "c", "d", "e", "f", "g", "h", "i", null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   255
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   256
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   257
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   258
    public void nullDisallowedN() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   259
        String[] array = stringArray.clone();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   260
        array[0] = null;
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   261
        Set.of(array);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   262
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   263
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   264
    @Test(expectedExceptions=NullPointerException.class)
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   265
    public void nullArrayDisallowed() {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   266
        Set.of((Object[])null);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   267
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   268
49283
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   269
    @Test(dataProvider="all", expectedExceptions=NullPointerException.class)
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   270
    public void containsNullShouldThrowNPE(Set<String> act, Set<String> exp) {
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   271
        act.contains(null);
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   272
    }
a14ede52a278 8193128: Reduce number of implementation classes returned by List/Set/Map.of()
redestad
parents: 48059
diff changeset
   273
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   274
    @Test(dataProvider="all")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   275
    public void serialEquality(Set<String> act, Set<String> exp) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   276
        // assume that act.equals(exp) tested elsewhere
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   277
        Set<String> copy = serialClone(act);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   278
        assertEquals(act, copy);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   279
        assertEquals(copy, exp);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   280
    }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   281
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   282
    @SuppressWarnings("unchecked")
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   283
    static <T> T serialClone(T obj) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   284
        try {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   285
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
48059
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   286
            try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   287
                oos.writeObject(obj);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   288
            }
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   289
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   290
            ObjectInputStream ois = new ObjectInputStream(bais);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   291
            return (T) ois.readObject();
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   292
        } catch (IOException | ClassNotFoundException e) {
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   293
            throw new AssertionError(e);
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   294
        }
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   295
    }
48059
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   296
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   297
    Set<Integer> genSet() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   298
        return new HashSet<>(Arrays.asList(1, 2, 3));
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
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   301
    @Test
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   302
    public void copyOfResultsEqual() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   303
        Set<Integer> orig = genSet();
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   304
        Set<Integer> copy = Set.copyOf(orig);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   305
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   306
        assertEquals(orig, copy);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   307
        assertEquals(copy, 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
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   310
    @Test
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   311
    public void copyOfModifiedUnequal() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   312
        Set<Integer> orig = genSet();
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   313
        Set<Integer> copy = Set.copyOf(orig);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   314
        orig.add(4);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   315
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   316
        assertNotEquals(orig, copy);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   317
        assertNotEquals(copy, orig);
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
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   320
    @Test
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   321
    public void copyOfIdentity() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   322
        Set<Integer> orig = genSet();
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   323
        Set<Integer> copy1 = Set.copyOf(orig);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   324
        Set<Integer> copy2 = Set.copyOf(copy1);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   325
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   326
        assertNotSame(orig, copy1);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   327
        assertSame(copy1, copy2);
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
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   330
    @Test(expectedExceptions=NullPointerException.class)
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   331
    public void copyOfRejectsNullCollection() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   332
        Set<Integer> set = Set.copyOf(null);
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   333
    }
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   334
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   335
    @Test(expectedExceptions=NullPointerException.class)
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   336
    public void copyOfRejectsNullElements() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   337
        Set<Integer> set = Set.copyOf(Arrays.asList(1, null, 3));
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   338
    }
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   339
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   340
    @Test
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   341
    public void copyOfAcceptsDuplicates() {
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   342
        Set<Integer> set = Set.copyOf(Arrays.asList(1, 1, 2, 3, 3, 3));
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   343
        assertEquals(set, Set.of(1, 2, 3));
6ee80cd217e0 8177290: add copy factory methods for unmodifiable List, Set, Map
smarks
parents: 47216
diff changeset
   344
    }
34527
e3caf3a43d09 8139232: JEP-269 initial API and skeleton implementations
smarks
parents:
diff changeset
   345
}