jdk/test/java/lang/module/ModuleDescriptorTest.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 44359 c6761862ca0b
child 45004 ea3137042a61
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
     2
 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
 * @test
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    26
 * @modules java.base/jdk.internal.module
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    27
 *          java.base/jdk.internal.misc
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
 * @run testng ModuleDescriptorTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
 * @summary Basic test for java.lang.module.ModuleDescriptor and its builder
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
    32
import java.io.ByteArrayOutputStream;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import java.io.InputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import java.lang.module.InvalidModuleDescriptorException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
import java.lang.module.ModuleDescriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
import java.lang.module.ModuleDescriptor.Builder;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
import java.lang.module.ModuleDescriptor.Exports;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
    39
import java.lang.module.ModuleDescriptor.Opens;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
import java.lang.module.ModuleDescriptor.Requires;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
import java.lang.module.ModuleDescriptor.Provides;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
import java.lang.module.ModuleDescriptor.Requires.Modifier;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
import java.lang.module.ModuleDescriptor.Version;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
import java.nio.ByteBuffer;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    45
import java.util.ArrayList;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
import java.util.EnumSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
import java.util.HashSet;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    49
import java.util.Iterator;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
    50
import java.util.List;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    51
import java.util.Objects;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
    52
import java.util.Optional;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
import java.util.Set;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    54
import java.util.stream.Collectors;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
import static java.lang.module.ModuleDescriptor.Requires.Modifier.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
    58
import jdk.internal.misc.JavaLangModuleAccess;
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    59
import jdk.internal.misc.SharedSecrets;
39050
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
    60
import jdk.internal.module.ModuleInfoWriter;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
import org.testng.annotations.DataProvider;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
@Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
public class ModuleDescriptorTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    @DataProvider(name = "invalidjavaidentifiers")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    public Object[][] invalidJavaIdentifiers() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        return new Object[][]{
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    72
            { null,             null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    73
            { "1",              null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    74
            { "1foo",           null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    75
            { ".foo",           null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    76
            { "foo.",           null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    77
            { "[foo]",          null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    78
            { "foo.1",          null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    79
            { "1foo.bar",       null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    80
            { "foo.1bar",       null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    81
            { "foo.[bar]",      null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    82
            { "foo..bar",       null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    83
            { "foo.bar.1",      null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    84
            { "foo.bar.1gus",   null },
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    85
            { "foo.bar.[gus]",  null },
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        };
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
    // requires
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    private Requires requires(Set<Modifier> mods, String mn) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    94
        return requires(mods, mn, null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
    97
    private Requires requires(Set<Modifier> mods, String mn, Version v) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    98
        Builder builder = ModuleDescriptor.newModule("m");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
    99
        if (v == null) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   100
            builder.requires(mods, mn);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   101
        } else {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   102
            builder.requires(mods, mn, v);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   103
        }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   104
        Set<Requires> requires = builder.build().requires();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   105
        assertTrue(requires.size() == 2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   106
        Iterator<Requires> iterator = requires.iterator();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   107
        Requires r = iterator.next();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   108
        if (r.name().equals("java.base")) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   109
            r = iterator.next();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   110
        } else {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   111
            Requires other = iterator.next();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   112
            assertEquals(other.name(), "java.base");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   113
        }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   114
        return r;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   115
    }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   116
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   117
    private Requires requires(String mn) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   118
        return requires(Collections.emptySet(), mn);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   121
    public void testRequiresWithRequires() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   122
        Requires r1 = requires("foo");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   123
        ModuleDescriptor descriptor = ModuleDescriptor.newModule("m").requires(r1).build();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   124
        Requires r2 = descriptor.requires().iterator().next();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   125
        assertEquals(r1, r2);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
    public void testRequiresWithNoModifiers() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        Requires r = requires(EnumSet.noneOf(Requires.Modifier.class), "foo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        assertEquals(r, r);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        assertTrue(r.compareTo(r) == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        assertTrue(r.modifiers().isEmpty());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
        assertEquals(r.name(), "foo");
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   134
        assertFalse(r.compiledVersion().isPresent());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
    public void testRequiresWithOneModifier() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   138
        Requires r = requires(EnumSet.of(TRANSITIVE), "foo");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        assertEquals(r, r);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        assertTrue(r.compareTo(r) == 0);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   141
        assertEquals(r.modifiers(), EnumSet.of(TRANSITIVE));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        assertEquals(r.name(), "foo");
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   143
        assertFalse(r.compiledVersion().isPresent());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
    public void testRequiresWithTwoModifiers() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   147
        Requires r = requires(EnumSet.of(TRANSITIVE, SYNTHETIC), "foo");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
        assertEquals(r, r);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        assertTrue(r.compareTo(r) == 0);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   150
        assertEquals(r.modifiers(), EnumSet.of(TRANSITIVE, SYNTHETIC));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        assertEquals(r.name(), "foo");
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   152
        assertFalse(r.compiledVersion().isPresent());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
    public void testRequiresWithAllModifiers() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        Requires r = requires(EnumSet.allOf(Modifier.class), "foo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        assertEquals(r, r);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
        assertTrue(r.compareTo(r) == 0);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   159
        assertEquals(r.modifiers(), EnumSet.of(TRANSITIVE, STATIC, SYNTHETIC, MANDATED));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        assertEquals(r.name(), "foo");
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   161
        assertFalse(r.compiledVersion().isPresent());
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   162
    }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   163
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   164
    public void testRequiresWithCompiledVersion() {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   165
        Version v = Version.parse("1.0");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   166
        Requires r = requires(Set.of(), "foo", v);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   167
        assertEquals(r, r);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   168
        assertTrue(r.compareTo(r) == 0);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   169
        assertEquals(r.modifiers(), Set.of());
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   170
        assertEquals(r.name(), "foo");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   171
        assertTrue(r.compiledVersion().isPresent());
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   172
        assertEquals(r.compiledVersion().get().toString(), "1.0");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
    @Test(expectedExceptions = IllegalStateException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
    public void testRequiresWithDuplicatesRequires() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   177
        Requires r = requires("foo");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   178
        ModuleDescriptor.newModule("m").requires(r).requires(r);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
    @Test(expectedExceptions = IllegalArgumentException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
    public void testRequiresSelfWithRequires() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   183
        Requires r = requires("foo");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   184
        ModuleDescriptor.newModule("foo").requires(r);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
    @Test(expectedExceptions = IllegalArgumentException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
    public void testRequiresSelfWithNoModifier() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   189
        ModuleDescriptor.newModule("m").requires("m");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
    @Test(expectedExceptions = IllegalArgumentException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
    public void testRequiresSelfWithOneModifier() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   194
        ModuleDescriptor.newModule("m").requires(Set.of(TRANSITIVE), "m");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
    @Test(expectedExceptions = IllegalArgumentException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
    public void testRequiresSelfWithAllModifiers() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   199
        ModuleDescriptor.newModule("m").requires(EnumSet.allOf(Modifier.class), "m");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
    @Test(dataProvider = "invalidjavaidentifiers",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
          expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    public void testRequiresWithBadModuleName(String mn, String ignore) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        requires(EnumSet.noneOf(Modifier.class), mn);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
    @Test(expectedExceptions = NullPointerException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
    public void testRequiresWithNullRequires() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   210
        ModuleDescriptor.newModule("m").requires((Requires) null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   213
    @Test(expectedExceptions = NullPointerException.class)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   214
    public void testRequiresWithNullModifiers() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   215
        ModuleDescriptor.newModule("m").requires(null, "foo");
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   216
    }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   217
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   218
    @Test(expectedExceptions = NullPointerException.class)
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   219
    public void testRequiresWithNullVersion() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   220
        ModuleDescriptor.newModule("m").requires(Set.of(), "foo", null);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   221
    }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   222
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
    public void testRequiresCompare() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        Requires r1 = requires(EnumSet.noneOf(Modifier.class), "foo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
        Requires r2 = requires(EnumSet.noneOf(Modifier.class), "bar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
        int n = "foo".compareTo("bar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        assertTrue(r1.compareTo(r2) == n);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        assertTrue(r2.compareTo(r1) == -n);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
39064
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   231
    public void testRequiresCompareWithDifferentModifiers() {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   232
        Requires r1 = requires(EnumSet.of(TRANSITIVE), "foo");
39064
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   233
        Requires r2 = requires(EnumSet.of(SYNTHETIC), "foo");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   234
        int n = Integer.compare(1 << TRANSITIVE.ordinal(), 1 << SYNTHETIC.ordinal());
39064
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   235
        assertTrue(r1.compareTo(r2) == n);
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   236
        assertTrue(r2.compareTo(r1) == -n);
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   237
    }
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   238
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   239
    public void testRequiresCompareWithSameModifiers() {
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   240
        Requires r1 = requires(EnumSet.of(SYNTHETIC), "foo");
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   241
        Requires r2 = requires(EnumSet.of(SYNTHETIC), "foo");
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   242
        assertTrue(r1.compareTo(r2) == 0);
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   243
        assertTrue(r2.compareTo(r1) == 0);
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   244
    }
45cbf2937973 8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents: 39050
diff changeset
   245
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   246
    public void testRequiresCompareWithSameCompiledVersion() {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   247
        Requires r1 = requires(Set.of(), "foo", Version.parse("2.0"));
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   248
        Requires r2 = requires(Set.of(), "foo", Version.parse("2.0"));
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   249
        assertTrue(r1.compareTo(r2) == 0);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   250
        assertTrue(r2.compareTo(r1) == 0);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   251
    }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   252
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   253
    public void testRequiresCompareWithDifferentCompiledVersion() {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   254
        Requires r1 = requires(Set.of(), "foo", Version.parse("1.0"));
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   255
        Requires r2 = requires(Set.of(), "foo", Version.parse("2.0"));
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   256
        assertTrue(r1.compareTo(r2) < 0);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   257
        assertTrue(r2.compareTo(r1) > 0);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   258
    }
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   259
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   260
    public void testRequiresEqualsAndHashCode() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   261
        Requires r1 = requires("foo");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   262
        Requires r2 = requires("foo");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   263
        assertEquals(r1, r2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   264
        assertTrue(r1.hashCode() == r2.hashCode());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   265
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   266
        r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   267
        r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   268
        assertEquals(r1, r2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   269
        assertTrue(r1.hashCode() == r2.hashCode());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   270
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   271
        r1 = requires("foo");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   272
        r2 = requires("bar");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   273
        assertNotEquals(r1, r2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   274
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   275
        r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   276
        r2 = requires(Set.of(), "foo");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   277
        assertNotEquals(r1, r2);
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   278
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   279
        Version v1 = Version.parse("1.0");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   280
        r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   281
        r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   282
        assertEquals(r1, r2);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   283
        assertTrue(r1.hashCode() == r2.hashCode());
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   284
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   285
        Version v2 = Version.parse("2.0");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   286
        r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   287
        r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v2);
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
   288
        assertNotEquals(r1, r2);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   289
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   290
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
    public void testRequiresToString() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
        Requires r = requires(EnumSet.noneOf(Modifier.class), "foo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   293
        assertTrue(r.toString().contains("foo"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   294
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   295
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   296
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   297
    // exports
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   298
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   299
    private Exports exports(Set<Exports.Modifier> mods, String pn) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   300
        return ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   301
            .exports(mods, pn)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   302
            .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   303
            .exports()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   304
            .iterator()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   305
            .next();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   306
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   307
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   308
    private Exports exports(String pn) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   309
        return exports(Set.of(), pn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   310
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   311
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   312
    private Exports exports(Set<Exports.Modifier> mods, String pn, String target) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   313
        return ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   314
            .exports(mods, pn, Set.of(target))
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   315
            .build()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   316
            .exports()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   317
            .iterator()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   318
            .next();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   319
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   320
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   321
    private Exports exports(String pn, String target) {
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   322
        return exports(Set.of(), pn, target);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   323
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   324
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   325
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   326
    public void testExportsExports() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   327
        Exports e1 = exports("p");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   328
        ModuleDescriptor descriptor = ModuleDescriptor.newModule("m").exports(e1).build();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   329
        Exports e2 = descriptor.exports().iterator().next();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   330
        assertEquals(e1, e2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   331
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   332
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   333
    public void testExportsToAll() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   334
        Exports e = exports("p");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   335
        assertEquals(e, e);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   336
        assertTrue(e.modifiers().isEmpty());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   337
        assertEquals(e.source(), "p");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   338
        assertFalse(e.isQualified());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   339
        assertTrue(e.targets().isEmpty());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   340
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   341
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   342
    public void testExportsToTarget() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   343
        Exports e = exports("p", "bar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   344
        assertEquals(e, e);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   345
        assertTrue(e.modifiers().isEmpty());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   346
        assertEquals(e.source(), "p");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   347
        assertTrue(e.isQualified());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   348
        assertTrue(e.targets().size() == 1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   349
        assertTrue(e.targets().contains("bar"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   350
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   351
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   352
    public void testExportsToTargets() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   353
        Set<String> targets = new HashSet<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   354
        targets.add("bar");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   355
        targets.add("gus");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   356
        Exports e
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   357
            = ModuleDescriptor.newModule("foo")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   358
                .exports("p", targets)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   359
                .build()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   360
                .exports()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   361
                .iterator()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   362
                .next();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   363
        assertEquals(e, e);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   364
        assertTrue(e.modifiers().isEmpty());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   365
        assertEquals(e.source(), "p");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   366
        assertTrue(e.isQualified());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   367
        assertTrue(e.targets().size() == 2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   368
        assertTrue(e.targets().contains("bar"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   369
        assertTrue(e.targets().contains("gus"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   370
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   371
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   372
    public void testExportsToAllWithModifier() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   373
        Exports e = exports(Set.of(Exports.Modifier.SYNTHETIC), "p");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   374
        assertEquals(e, e);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   375
        assertTrue(e.modifiers().size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   376
        assertTrue(e.modifiers().contains(Exports.Modifier.SYNTHETIC));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   377
        assertEquals(e.source(), "p");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   378
        assertFalse(e.isQualified());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   379
        assertTrue(e.targets().isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   380
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   381
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   382
    public void testExportsToTargetWithModifier() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   383
        Exports e = exports(Set.of(Exports.Modifier.SYNTHETIC), "p", "bar");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   384
        assertEquals(e, e);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   385
        assertTrue(e.modifiers().size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   386
        assertTrue(e.modifiers().contains(Exports.Modifier.SYNTHETIC));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   387
        assertEquals(e.source(), "p");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   388
        assertTrue(e.isQualified());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   389
        assertTrue(e.targets().size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   390
        assertTrue(e.targets().contains("bar"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   391
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   392
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   393
    @Test(expectedExceptions = IllegalStateException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   394
    public void testExportsWithDuplicate1() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   395
        Exports e = exports("p");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   396
        ModuleDescriptor.newModule("foo").exports(e).exports(e);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   397
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   398
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   399
    @Test(expectedExceptions = IllegalStateException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   400
    public void testExportsWithDuplicate2() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   401
        ModuleDescriptor.newModule("foo").exports("p").exports("p");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   402
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   403
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   404
    @Test(expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   405
    public void testExportsWithEmptySet() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   406
        ModuleDescriptor.newModule("foo").exports("p", Collections.emptySet());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   407
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   408
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   409
    @Test(dataProvider = "invalidjavaidentifiers",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   410
          expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   411
    public void testExportsWithBadName(String pn, String ignore) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   412
        ModuleDescriptor.newModule("foo").exports(pn);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   413
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   414
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   415
    @Test(expectedExceptions = NullPointerException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   416
    public void testExportsWithNullExports() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   417
        ModuleDescriptor.newModule("foo").exports((Exports) null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   418
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   419
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   420
    @Test(expectedExceptions = NullPointerException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   421
    public void testExportsWithNullTargets() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   422
        ModuleDescriptor.newModule("foo").exports("p", (Set<String>) null);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   423
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   424
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   425
    public void testExportsCompare() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   426
        Exports e1 = exports("p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   427
        Exports e2 = exports("p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   428
        assertEquals(e1, e2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   429
        assertTrue(e1.hashCode() == e2.hashCode());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   430
        assertTrue(e1.compareTo(e2) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   431
        assertTrue(e2.compareTo(e1) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   432
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   433
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   434
    public void testExportsCompareWithSameModifiers() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   435
        Exports e1 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   436
        Exports e2 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   437
        assertEquals(e1, e2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   438
        assertTrue(e1.hashCode() == e2.hashCode());
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   439
        assertTrue(e1.compareTo(e2) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   440
        assertTrue(e2.compareTo(e1) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   441
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   442
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   443
    public void testExportsCompareWithDifferentModifiers() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   444
        Exports e1 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   445
        Exports e2 = exports("p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   446
        assertNotEquals(e1, e2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   447
        assertTrue(e1.compareTo(e2) == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   448
        assertTrue(e2.compareTo(e1) == -1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   449
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   450
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   451
    public void testExportsCompareWithSameTargets() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   452
        Exports e1 = exports("p", "x");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   453
        Exports e2 = exports("p", "x");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   454
        assertEquals(e1, e2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   455
        assertTrue(e1.hashCode() == e2.hashCode());
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   456
        assertTrue(e1.compareTo(e2) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   457
        assertTrue(e2.compareTo(e1) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   458
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   459
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   460
    public void testExportsCompareWithDifferentTargets() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   461
        Exports e1 = exports("p", "y");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   462
        Exports e2 = exports("p", "x");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   463
        assertNotEquals(e1, e2);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   464
        assertTrue(e1.compareTo(e2) == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   465
        assertTrue(e2.compareTo(e1) == -1);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   466
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   467
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   468
    public void testExportsToString() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   469
        String s = ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   470
            .exports("p1", Set.of("bar"))
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   471
            .build()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   472
            .exports()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   473
            .iterator()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   474
            .next()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   475
            .toString();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   476
        assertTrue(s.contains("p1"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   477
        assertTrue(s.contains("bar"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   478
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   479
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   480
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   481
    // opens
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   482
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   483
    private Opens opens(Set<Opens.Modifier> mods, String pn) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   484
        return ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   485
                .opens(mods, pn)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   486
                .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   487
                .opens()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   488
                .iterator()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   489
                .next();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   490
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   491
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   492
    private Opens opens(String pn) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   493
        return opens(Set.of(), pn);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   494
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   495
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   496
    private Opens opens(Set<Opens.Modifier> mods, String pn, String target) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   497
        return ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   498
                .opens(mods, pn, Set.of(target))
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   499
                .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   500
                .opens()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   501
                .iterator()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   502
                .next();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   503
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   504
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   505
    private Opens opens(String pn, String target) {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   506
        return opens(Set.of(), pn, target);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   507
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   508
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   509
    public void testOpensOpens() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   510
        Opens o1 = opens("p");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   511
        ModuleDescriptor descriptor = ModuleDescriptor.newModule("m").opens(o1).build();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   512
        Opens o2 = descriptor.opens().iterator().next();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   513
        assertEquals(o1, o2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   514
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   515
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   516
    public void testOpensToAll() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   517
        Opens o = opens("p");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   518
        assertEquals(o, o);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   519
        assertTrue(o.modifiers().isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   520
        assertEquals(o.source(), "p");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   521
        assertFalse(o.isQualified());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   522
        assertTrue(o.targets().isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   523
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   524
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   525
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   526
    public void testOpensToTarget() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   527
        Opens o = opens("p", "bar");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   528
        assertEquals(o, o);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   529
        assertTrue(o.modifiers().isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   530
        assertEquals(o.source(), "p");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   531
        assertTrue(o.isQualified());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   532
        assertTrue(o.targets().size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   533
        assertTrue(o.targets().contains("bar"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   534
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   535
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   536
    public void testOpensToTargets() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   537
        Set<String> targets = new HashSet<>();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   538
        targets.add("bar");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   539
        targets.add("gus");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   540
        Opens o = ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   541
                .opens("p", targets)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   542
                .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   543
                .opens()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   544
                .iterator()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   545
                .next();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   546
        assertEquals(o, o);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   547
        assertTrue(o.modifiers().isEmpty());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   548
        assertEquals(o.source(), "p");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   549
        assertTrue(o.isQualified());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   550
        assertTrue(o.targets().size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   551
        assertTrue(o.targets().contains("bar"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   552
        assertTrue(o.targets().contains("gus"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   553
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   554
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   555
    @Test(expectedExceptions = IllegalStateException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   556
    public void testOpensWithDuplicate1() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   557
        Opens o = opens("p");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   558
        ModuleDescriptor.newModule("foo").opens(o).opens(o);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   559
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   560
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   561
    @Test(expectedExceptions = IllegalStateException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   562
    public void testOpensWithDuplicate2() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   563
        ModuleDescriptor.newModule("foo").opens("p").opens("p");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   564
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   565
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   566
    @Test(expectedExceptions = IllegalArgumentException.class )
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   567
    public void testOpensWithEmptySet() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   568
        ModuleDescriptor.newModule("foo").opens("p", Collections.emptySet());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   569
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   570
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   571
    @Test(dataProvider = "invalidjavaidentifiers",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   572
            expectedExceptions = IllegalArgumentException.class )
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   573
    public void testOpensWithBadName(String pn, String ignore) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   574
        ModuleDescriptor.newModule("foo").opens(pn);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   575
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   576
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   577
    @Test(expectedExceptions = NullPointerException.class )
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   578
    public void testOpensWithNullExports() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   579
        ModuleDescriptor.newModule("foo").opens((Opens) null);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   580
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   581
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   582
    @Test(expectedExceptions = NullPointerException.class )
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   583
    public void testOpensWithNullTargets() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   584
        ModuleDescriptor.newModule("foo").opens("p", (Set<String>) null);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   585
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   586
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   587
    public void testOpensCompare() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   588
        Opens o1 = opens("p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   589
        Opens o2 = opens("p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   590
        assertEquals(o1, o2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   591
        assertTrue(o1.hashCode() == o2.hashCode());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   592
        assertTrue(o1.compareTo(o2) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   593
        assertTrue(o2.compareTo(o1) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   594
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   595
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   596
    public void testOpensCompareWithSameModifiers() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   597
        Opens o1 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   598
        Opens o2 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   599
        assertEquals(o1, o2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   600
        assertTrue(o1.hashCode() == o2.hashCode());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   601
        assertTrue(o1.compareTo(o2) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   602
        assertTrue(o2.compareTo(o1) == 0);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   603
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   604
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   605
    public void testOpensCompareWithDifferentModifiers() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   606
        Opens o1 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   607
        Opens o2 = opens("p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   608
        assertNotEquals(o1, o2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   609
        assertTrue(o1.compareTo(o2) == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   610
        assertTrue(o2.compareTo(o1) == -1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   611
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   612
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   613
    public void testOpensCompareWithSameTargets() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   614
        Opens o1 = opens("p", "x");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   615
        Opens o2 = opens("p", "x");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   616
        assertEquals(o1, o2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   617
        assertTrue(o1.hashCode() == o2.hashCode());
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   618
        assertTrue(o1.compareTo(o2) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   619
        assertTrue(o2.compareTo(o1) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   620
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   621
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   622
    public void testOpensCompareWithDifferentTargets() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   623
        Opens o1 = opens("p", "y");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   624
        Opens o2 = opens("p", "x");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   625
        assertNotEquals(o1, o2);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   626
        assertTrue(o1.compareTo(o2) == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   627
        assertTrue(o2.compareTo(o1) == -1);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   628
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   629
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   630
    public void testOpensToString() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   631
        String s = ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   632
                .opens("p1", Set.of("bar"))
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   633
                .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   634
                .opens()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   635
                .iterator()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   636
                .next()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   637
                .toString();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   638
        assertTrue(s.contains("p1"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   639
        assertTrue(s.contains("bar"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   640
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   641
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   642
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   643
    // uses
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   644
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   645
    public void testUses() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   646
        Set<String> uses
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   647
            = ModuleDescriptor.newModule("foo")
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   648
                .uses("p.S")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   649
                .uses("q.S")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   650
                .build()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   651
                .uses();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   652
        assertTrue(uses.size() == 2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   653
        assertTrue(uses.contains("p.S"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   654
        assertTrue(uses.contains("q.S"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   655
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   656
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   657
    @Test(expectedExceptions = IllegalStateException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   658
    public void testUsesWithDuplicate() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   659
        ModuleDescriptor.newModule("foo").uses("p.S").uses("p.S");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   660
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   661
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   662
    @Test(expectedExceptions = IllegalArgumentException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   663
    public void testUsesWithSimpleIdentifier() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   664
        ModuleDescriptor.newModule("foo").uses("S");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   665
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   666
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   667
    @Test(dataProvider = "invalidjavaidentifiers",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   668
          expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   669
    public void testUsesWithBadName(String service, String ignore) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   670
        ModuleDescriptor.newModule("foo").uses(service);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   671
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   672
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   673
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   674
    // provides
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   675
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   676
    private Provides provides(String st, String pc) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   677
        return ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   678
            .provides(st, List.of(pc))
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   679
            .build()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   680
            .provides()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   681
            .iterator()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   682
            .next();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   683
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   684
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   685
    private Provides provides(String st, List<String> pns) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   686
        return ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   687
                .provides(st, pns)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   688
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   689
                .provides()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   690
                .iterator()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   691
                .next();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   692
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   693
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   694
    public void testProvidesWithProvides() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   695
        Provides p1 = provides("p.S", "q.S1");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   696
        ModuleDescriptor descriptor = ModuleDescriptor.newModule("m")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   697
                .provides(p1)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   698
                .build();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   699
        Provides p2 = descriptor.provides().iterator().next();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   700
        assertEquals(p1, p2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   701
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   702
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   703
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   704
    public void testProvides() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   705
        Set<Provides> set = ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   706
                .provides("p.S", List.of("q.P1", "q.P2"))
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   707
                .build()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   708
                .provides();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   709
        assertTrue(set.size() == 1);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   710
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   711
        Provides p = set.iterator().next();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   712
        assertEquals(p, p);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   713
        assertEquals(p.service(), "p.S");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   714
        assertTrue(p.providers().size() == 2);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   715
        assertEquals(p.providers().get(0), "q.P1");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   716
        assertEquals(p.providers().get(1), "q.P2");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   717
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   718
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   719
    @Test(expectedExceptions = IllegalStateException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   720
    public void testProvidesWithDuplicateProvides() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   721
        Provides p = provides("p.S", "q.S2");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   722
        ModuleDescriptor.newModule("m").provides("p.S", List.of("q.S1")).provides(p);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   723
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   724
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   725
    @Test(expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   726
    public void testProvidesWithEmptySet() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   727
        ModuleDescriptor.newModule("foo").provides("p.Service", Collections.emptyList());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   728
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   729
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   730
    @Test(expectedExceptions = IllegalArgumentException.class )
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   731
    public void testProvidesWithSimpleIdentifier1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   732
        ModuleDescriptor.newModule("foo").provides("S", List.of("q.P"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   733
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   734
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   735
    @Test(expectedExceptions = IllegalArgumentException.class )
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   736
    public void testProvidesWithSimpleIdentifier2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   737
        ModuleDescriptor.newModule("foo").provides("p.S", List.of("P"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   738
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   739
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   740
    @Test(dataProvider = "invalidjavaidentifiers",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   741
          expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   742
    public void testProvidesWithBadService(String service, String ignore) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   743
        ModuleDescriptor.newModule("foo").provides(service, List.of("p.Provider"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   744
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   745
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   746
    @Test(dataProvider = "invalidjavaidentifiers",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   747
          expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   748
    public void testProvidesWithBadProvider(String provider, String ignore) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   749
        List<String> names = new ArrayList<>(); // allows nulls
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   750
        names.add(provider);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   751
        ModuleDescriptor.newModule("foo").provides("p.Service", names);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   752
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   753
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   754
    @Test(expectedExceptions = NullPointerException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   755
    public void testProvidesWithNullProvides() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   756
        ModuleDescriptor.newModule("foo").provides((Provides) null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   757
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   758
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   759
    @Test(expectedExceptions = NullPointerException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   760
    public void testProvidesWithNullProviders() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   761
        ModuleDescriptor.newModule("foo").provides("p.S", (List<String>) null);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   762
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   763
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   764
    public void testProvidesCompare() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   765
        Provides p1 = provides("p.S", "q.S1");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   766
        Provides p2 = provides("p.S", "q.S1");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   767
        assertEquals(p1, p2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   768
        assertTrue(p1.hashCode() == p2.hashCode());
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   769
        assertTrue(p1.compareTo(p2) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   770
        assertTrue(p2.compareTo(p1) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   771
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   772
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   773
    public void testProvidesCompareWithDifferentService() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   774
        Provides p1 = provides("p.S2", "q.S1");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   775
        Provides p2 = provides("p.S1", "q.S1");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   776
        assertNotEquals(p1, p2);
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   777
        assertTrue(p1.compareTo(p2) == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   778
        assertTrue(p2.compareTo(p1) == -1);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   779
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   780
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   781
    public void testProvidesCompareWithDifferentProviders1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   782
        Provides p1 = provides("p.S", "q.S2");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   783
        Provides p2 = provides("p.S", "q.S1");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   784
        assertNotEquals(p1, p2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   785
        assertTrue(p1.compareTo(p2) == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   786
        assertTrue(p2.compareTo(p1) == -1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   787
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   788
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   789
    public void testProvidesCompareWithDifferentProviders2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   790
        Provides p1 = provides("p.S", List.of("q.S1", "q.S2"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   791
        Provides p2 = provides("p.S", "q.S1");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   792
        assertNotEquals(p1, p2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   793
        assertTrue(p1.compareTo(p2) == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   794
        assertTrue(p2.compareTo(p1) == -1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   795
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   796
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   797
    // packages
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   798
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   799
    public void testPackages1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   800
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   801
                .packages(Set.of("p", "q"))
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   802
                .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   803
                .packages();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   804
        assertTrue(packages.size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   805
        assertTrue(packages.contains("p"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   806
        assertTrue(packages.contains("q"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   807
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   808
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   809
    public void testPackages2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   810
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   811
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   812
                .packages(Set.of("q"))
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   813
                .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   814
                .packages();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   815
        assertTrue(packages.size() == 2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   816
        assertTrue(packages.contains("p"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   817
        assertTrue(packages.contains("q"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   818
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   819
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   820
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   821
    public void testPackagesWithEmptySet() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   822
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   823
                .packages(Collections.emptySet())
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   824
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   825
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   826
        assertTrue(packages.size() == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   827
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   828
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   829
    public void testPackagesDuplicate() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   830
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   831
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   832
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   833
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   834
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   835
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   836
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   837
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   838
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   839
    public void testPackagesAndExportsPackage1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   840
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   841
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   842
                .exports("p")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   843
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   844
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   845
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   846
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   847
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   848
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   849
    public void testPackagesAndExportsPackage2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   850
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   851
                .exports("p")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   852
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   853
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   854
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   855
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   856
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   857
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   858
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   859
    public void testPackagesAndOpensPackage1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   860
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   861
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   862
                .opens("p")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   863
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   864
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   865
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   866
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   867
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   868
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   869
    public void testPackagesAndOpensPackage2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   870
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   871
                .opens("p")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   872
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   873
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   874
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   875
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   876
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   877
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   878
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   879
    public void testPackagesAndProvides1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   880
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   881
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   882
                .provides("q.S", List.of("p.T"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   883
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   884
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   885
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   886
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   887
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   888
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   889
    public void testPackagesAndProvides2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   890
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   891
                .provides("q.S", List.of("p.T"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   892
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   893
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   894
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   895
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   896
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   897
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   898
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   899
    public void testPackagesAndMainClass1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   900
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   901
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   902
                .mainClass("p.Main")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   903
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   904
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   905
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   906
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   907
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   908
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   909
    public void testPackagesAndMainClass2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   910
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   911
                .mainClass("p.Main")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   912
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   913
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   914
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   915
        assertTrue(packages.size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   916
        assertTrue(packages.contains("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   917
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   918
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   919
    public void testPackagesAndAll() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   920
        Set<String> packages = ModuleDescriptor.newModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   921
                .exports("p1")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   922
                .opens("p2")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   923
                .packages(Set.of("p3"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   924
                .provides("q.S", List.of("p4.T"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   925
                .mainClass("p5.Main")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   926
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   927
                .packages();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   928
        assertTrue(Objects.equals(packages, Set.of("p1", "p2", "p3", "p4", "p5")));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   929
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   930
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   931
    @Test(dataProvider = "invalidjavaidentifiers",
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   932
          expectedExceptions = IllegalArgumentException.class )
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   933
    public void testPackagesWithBadName(String pn, String ignore) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   934
        Set<String> pkgs = new HashSet<>();  // allows nulls
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   935
        pkgs.add(pn);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   936
        ModuleDescriptor.newModule("foo").packages(pkgs);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   937
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   938
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   939
    // name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   940
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   941
    public void testModuleName() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   942
        String mn = ModuleDescriptor.newModule("foo").build().name();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   943
        assertEquals(mn, "foo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   944
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   945
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   946
    @Test(dataProvider = "invalidjavaidentifiers",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   947
          expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   948
    public void testBadModuleName(String mn, String ignore) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   949
        ModuleDescriptor.newModule(mn);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   950
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   951
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   952
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   953
    // version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   954
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   955
    public void testVersion1() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   956
        Version v1 = Version.parse("1.0");
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   957
        Version v2 = ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   958
                .version(v1)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   959
                .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   960
                .version()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   961
                .get();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   962
        assertEquals(v1, v2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   963
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   964
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   965
    public void testVersion2() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   966
        String vs = "1.0";
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   967
        Version v1 = ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   968
                .version(vs)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   969
                .build()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   970
                .version()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
   971
                .get();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   972
        Version v2 = Version.parse(vs);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   973
        assertEquals(v1, v2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   974
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   975
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   976
    @Test(expectedExceptions = NullPointerException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   977
    public void testNullVersion1() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   978
        ModuleDescriptor.newModule("foo").version((Version) null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   979
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   980
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   981
    @Test(expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   982
    public void testNullVersion2() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   983
        ModuleDescriptor.newModule("foo").version((String) null);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   984
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   985
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   986
    @Test(expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   987
    public void testEmptyVersion() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
   988
        ModuleDescriptor.newModule("foo").version("");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   989
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   990
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   991
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   992
    @DataProvider(name = "unparseableVersions")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   993
    public Object[][] unparseableVersions() {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   994
        return new Object[][]{
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   995
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   996
                { null,  "A1" },    // no version < unparseable
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   997
                { "A1",  "A2" },    // unparseable < unparseable
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   998
                { "A1",  "1.0" },   // unparseable < parseable
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
   999
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1000
        };
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1001
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1002
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1003
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1004
     * Basic test for unparseable module versions
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1005
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1006
    @Test(dataProvider = "unparseableVersions")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1007
    public void testUnparseableModuleVersion(String vs1, String vs2) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1008
        ModuleDescriptor descriptor1 = newModule("m", vs1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1009
        ModuleDescriptor descriptor2 = newModule("m", vs2);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1010
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1011
        if (vs1 != null && !isParsableVersion(vs1)) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1012
            assertFalse(descriptor1.version().isPresent());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1013
            assertTrue(descriptor1.rawVersion().isPresent());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1014
            assertEquals(descriptor1.rawVersion().get(), vs1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1015
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1016
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1017
        if (vs2 != null && !isParsableVersion(vs2)) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1018
            assertFalse(descriptor2.version().isPresent());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1019
            assertTrue(descriptor2.rawVersion().isPresent());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1020
            assertEquals(descriptor2.rawVersion().get(), vs2);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1021
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1022
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1023
        assertFalse(descriptor1.equals(descriptor2));
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1024
        assertFalse(descriptor2.equals(descriptor1));
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1025
        assertTrue(descriptor1.compareTo(descriptor2) == -1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1026
        assertTrue(descriptor2.compareTo(descriptor1) == 1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1027
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1028
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1029
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1030
     * Basic test for requiring a module with an unparseable version recorded
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1031
     * at compile version.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1032
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1033
    @Test(dataProvider = "unparseableVersions")
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1034
    public void testUnparseableCompiledVersion(String vs1, String vs2) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1035
        Requires r1 = newRequires("m", vs1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1036
        Requires r2 = newRequires("m", vs2);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1037
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1038
        if (vs1 != null && !isParsableVersion(vs1)) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1039
            assertFalse(r1.compiledVersion().isPresent());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1040
            assertTrue(r1.rawCompiledVersion().isPresent());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1041
            assertEquals(r1.rawCompiledVersion().get(), vs1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1042
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1043
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1044
        if (vs2 != null && !isParsableVersion(vs2)) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1045
            assertFalse(r2.compiledVersion().isPresent());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1046
            assertTrue(r2.rawCompiledVersion().isPresent());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1047
            assertEquals(r2.rawCompiledVersion().get(), vs2);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1048
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1049
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1050
        assertFalse(r1.equals(r2));
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1051
        assertFalse(r2.equals(r1));
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1052
        assertTrue(r1.compareTo(r2) == -1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1053
        assertTrue(r2.compareTo(r1) == 1);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1054
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1055
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1056
    private ModuleDescriptor newModule(String name, String vs) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1057
        JavaLangModuleAccess JLMA = SharedSecrets.getJavaLangModuleAccess();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1058
        Builder builder = JLMA.newModuleBuilder(name, false, Set.of());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1059
        if (vs != null)
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1060
            builder.version(vs);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1061
        builder.requires("java.base");
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1062
        ByteBuffer bb = ModuleInfoWriter.toByteBuffer(builder.build());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1063
        return ModuleDescriptor.read(bb);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1064
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1065
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1066
    private Requires newRequires(String name, String vs) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1067
        JavaLangModuleAccess JLMA = SharedSecrets.getJavaLangModuleAccess();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1068
        Builder builder = JLMA.newModuleBuilder("foo", false, Set.of());
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1069
        if (vs == null) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1070
            builder.requires(name);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1071
        } else {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1072
            JLMA.requires(builder, Set.of(), name, vs);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1073
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1074
        Set<ModuleDescriptor.Requires> requires = builder.build().requires();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1075
        Iterator<ModuleDescriptor.Requires> iterator = requires.iterator();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1076
        ModuleDescriptor.Requires r = iterator.next();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1077
        if (r.name().equals("java.base")) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1078
            r = iterator.next();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1079
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1080
        return r;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1081
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1082
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1083
    private boolean isParsableVersion(String vs) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1084
        try {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1085
            Version.parse(vs);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1086
            return true;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1087
        } catch (IllegalArgumentException e) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1088
            return false;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1089
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1090
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1091
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1092
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1093
    // toNameAndVersion
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1094
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1095
    public void testToNameAndVersion() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1096
        ModuleDescriptor md1 = ModuleDescriptor.newModule("foo").build();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1097
        assertEquals(md1.toNameAndVersion(), "foo");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1098
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1099
        ModuleDescriptor md2 = ModuleDescriptor.newModule("foo").version("1.0").build();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1100
        assertEquals(md2.toNameAndVersion(), "foo@1.0");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1101
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1102
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1103
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1104
    // open modules
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1105
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1106
    public void testOpenModule() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1107
        ModuleDescriptor descriptor = ModuleDescriptor.newOpenModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1108
                .requires("bar")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1109
                .exports("p")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1110
                .provides("p.Service", List.of("q.ServiceImpl"))
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1111
                .build();
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1112
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1113
        // modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1114
        assertTrue(descriptor.modifiers().contains(ModuleDescriptor.Modifier.OPEN));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1115
        assertTrue(descriptor.isOpen());
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1116
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1117
        // requires
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1118
        assertTrue(descriptor.requires().size() == 2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1119
        Set<String> names = descriptor.requires()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1120
                .stream()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1121
                .map(Requires::name)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1122
                .collect(Collectors.toSet());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1123
        assertEquals(names, Set.of("bar", "java.base"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1124
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1125
        // packages
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1126
        assertEquals(descriptor.packages(), Set.of("p", "q"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1127
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1128
        // exports
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1129
        assertTrue(descriptor.exports().size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1130
        names = descriptor.exports()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1131
                .stream()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1132
                .map(Exports::source)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1133
                .collect(Collectors.toSet());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1134
        assertEquals(names, Set.of("p"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1135
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1136
        // opens
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1137
        assertTrue(descriptor.opens().isEmpty());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1138
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1139
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1140
    @Test(expectedExceptions = IllegalStateException.class)
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1141
    public void testOpensOnOpenModule1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1142
        ModuleDescriptor.newOpenModule("foo").opens("p");
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1143
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1144
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1145
    @Test(expectedExceptions = IllegalStateException.class)
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1146
    public void testOpensOnOpenModule2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1147
        ModuleDescriptor.newOpenModule("foo").opens("p", Set.of("bar"));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1148
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1149
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1150
    public void testIsOpen() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1151
        assertFalse(ModuleDescriptor.newModule("m").build().isOpen());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1152
        assertFalse(ModuleDescriptor.newAutomaticModule("m").build().isOpen());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1153
        assertTrue(ModuleDescriptor.newOpenModule("m").build().isOpen());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1154
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1155
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1156
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1157
    // automatic modules
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1158
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1159
    public void testAutomaticModule() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1160
        ModuleDescriptor descriptor = ModuleDescriptor.newAutomaticModule("foo")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1161
                .packages(Set.of("p"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1162
                .provides("p.Service", List.of("q.ServiceImpl"))
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1163
                .build();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1164
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1165
        // modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1166
        assertTrue(descriptor.modifiers().contains(ModuleDescriptor.Modifier.AUTOMATIC));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1167
        assertTrue(descriptor.isAutomatic());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1168
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1169
        // requires
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1170
        assertTrue(descriptor.requires().size() == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1171
        Set<String> names = descriptor.requires()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1172
                .stream()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1173
                .map(Requires::name)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1174
                .collect(Collectors.toSet());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1175
        assertEquals(names, Set.of("java.base"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1176
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1177
        // packages
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1178
        assertEquals(descriptor.packages(), Set.of("p", "q"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1179
        assertTrue(descriptor.exports().isEmpty());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1180
        assertTrue(descriptor.opens().isEmpty());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1181
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1182
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1183
    @Test(expectedExceptions = IllegalStateException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1184
    public void testRequiresOnAutomaticModule() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1185
        ModuleDescriptor.newAutomaticModule("foo").requires("java.base");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1186
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1187
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1188
    @Test(expectedExceptions = IllegalStateException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1189
    public void testExportsOnAutomaticModule1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1190
        ModuleDescriptor.newAutomaticModule("foo").exports("p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1191
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1192
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1193
    @Test(expectedExceptions = IllegalStateException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1194
    public void testExportsOnAutomaticModule2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1195
        ModuleDescriptor.newAutomaticModule("foo").exports("p", Set.of("bar"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1196
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1197
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1198
    @Test(expectedExceptions = IllegalStateException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1199
    public void testOpensOnAutomaticModule1() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1200
        ModuleDescriptor.newAutomaticModule("foo").opens("p");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1201
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1202
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1203
    @Test(expectedExceptions = IllegalStateException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1204
    public void testOpensOnAutomaticModule2() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1205
        ModuleDescriptor.newAutomaticModule("foo").opens("p", Set.of("bar"));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1206
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1207
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1208
    @Test(expectedExceptions = IllegalStateException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1209
    public void testUsesOnAutomaticModule() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1210
        ModuleDescriptor.newAutomaticModule("foo").uses("p.Service");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1211
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1212
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1213
    public void testIsAutomatic() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1214
        ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("foo").build();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1215
        assertFalse(descriptor1.isAutomatic());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1216
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1217
        ModuleDescriptor descriptor2 = ModuleDescriptor.newOpenModule("foo").build();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1218
        assertFalse(descriptor2.isAutomatic());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1219
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1220
        ModuleDescriptor descriptor3 = ModuleDescriptor.newAutomaticModule("foo").build();
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1221
        assertTrue(descriptor3.isAutomatic());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1222
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1223
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1224
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1225
    // newModule with modifiers
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1226
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1227
    public void testNewModuleToBuildAutomaticModule() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1228
        Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.AUTOMATIC);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1229
        ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo", ms).build();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1230
        assertTrue(descriptor.modifiers().equals(ms));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1231
        assertTrue(descriptor.isAutomatic());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1232
    }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1233
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1234
    public void testNewModuleToBuildOpenModule() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1235
        Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.OPEN);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1236
        ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo", ms).build();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1237
        assertTrue(descriptor.modifiers().equals(ms));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1238
        assertTrue(descriptor.isOpen());
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1239
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1240
        ms = Set.of(ModuleDescriptor.Modifier.OPEN, ModuleDescriptor.Modifier.SYNTHETIC);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1241
        descriptor = ModuleDescriptor.newModule("foo", ms).build();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1242
        assertTrue(descriptor.modifiers().equals(ms));
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1243
        assertTrue(descriptor.isOpen());
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1244
    }
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1245
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1246
    @Test(expectedExceptions = IllegalArgumentException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1247
    public void testNewModuleToBuildAutomaticAndOpenModule() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1248
        Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.AUTOMATIC,
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1249
                                                   ModuleDescriptor.Modifier.OPEN);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1250
        ModuleDescriptor.newModule("foo", ms);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1251
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1252
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1253
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1254
    // mainClass
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1255
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1256
    public void testMainClass() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1257
        String mainClass
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1258
            = ModuleDescriptor.newModule("foo").mainClass("p.Main").build().mainClass().get();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1259
        assertEquals(mainClass, "p.Main");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1260
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1261
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1262
    @Test(expectedExceptions = IllegalArgumentException.class)
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1263
    public void testMainClassWithSimpleIdentifier() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1264
        ModuleDescriptor.newModule("foo").mainClass("Main");
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1265
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1266
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1267
    @Test(dataProvider = "invalidjavaidentifiers",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1268
          expectedExceptions = IllegalArgumentException.class )
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1269
    public void testMainClassWithBadName(String mainClass, String ignore) {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1270
        Builder builder = ModuleDescriptor.newModule("foo");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1271
        builder.mainClass(mainClass);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1272
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1273
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1274
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1275
    // reads
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1276
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1277
    private static InputStream EMPTY_INPUT_STREAM = new InputStream() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1278
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1279
        public int read() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1280
            return -1;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1281
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1282
    };
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1283
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1284
    private static InputStream FAILING_INPUT_STREAM = new InputStream() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1285
        @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1286
        public int read() throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1287
            throw new IOException();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1288
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1289
    };
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1290
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1291
    /**
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1292
     * Basic test reading module-info.class
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1293
     */
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 42338
diff changeset
  1294
    public void testRead() throws Exception {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1295
        Module base = Object.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1296
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1297
        try (InputStream in = base.getResourceAsStream("module-info.class")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1298
            ModuleDescriptor descriptor = ModuleDescriptor.read(in);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1299
            assertTrue(in.read() == -1); // all bytes read
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1300
            assertEquals(descriptor.name(), "java.base");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1301
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1302
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1303
        try (InputStream in = base.getResourceAsStream("module-info.class")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1304
            ByteBuffer bb = ByteBuffer.wrap(in.readAllBytes());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1305
            ModuleDescriptor descriptor = ModuleDescriptor.read(bb);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1306
            assertFalse(bb.hasRemaining()); // no more remaining bytes
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1307
            assertEquals(descriptor.name(), "java.base");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1308
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1309
    }
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43712
diff changeset
  1310
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1311
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1312
     * Test ModuleDescriptor with a packager finder
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1313
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1314
    public void testReadsWithPackageFinder() throws Exception {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1315
        ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1316
                .requires("java.base")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1317
                .build();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1318
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1319
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1320
        ModuleInfoWriter.write(descriptor, baos);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1321
        ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1322
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1323
        descriptor = ModuleDescriptor.read(bb, () -> Set.of("p", "q"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1324
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1325
        assertTrue(descriptor.packages().size() == 2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1326
        assertTrue(descriptor.packages().contains("p"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1327
        assertTrue(descriptor.packages().contains("q"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1328
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1329
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1330
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1331
     * Test ModuleDescriptor with a packager finder that doesn't return the
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1332
     * complete set of packages.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1333
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1334
    @Test(expectedExceptions = InvalidModuleDescriptorException.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1335
    public void testReadsWithBadPackageFinder() throws Exception {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1336
        ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1337
                .requires("java.base")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1338
                .exports("p")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1339
                .build();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1340
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1341
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1342
        ModuleInfoWriter.write(descriptor, baos);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1343
        ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1344
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1345
        // package finder returns a set that doesn't include p
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 39064
diff changeset
  1346
        ModuleDescriptor.read(bb, () -> Set.of("q"));
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1347
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1348
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1349
    @Test(expectedExceptions = InvalidModuleDescriptorException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1350
    public void testReadFromEmptyInputStream() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1351
        ModuleDescriptor.read(EMPTY_INPUT_STREAM);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1352
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1353
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1354
    @Test(expectedExceptions = IOException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1355
    public void testReadFromFailingInputStream() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1356
        ModuleDescriptor.read(FAILING_INPUT_STREAM);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1357
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1358
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1359
    @Test(expectedExceptions = InvalidModuleDescriptorException.class)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1360
    public void testReadFromEmptyBuffer() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1361
        ByteBuffer bb = ByteBuffer.allocate(0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1362
        ModuleDescriptor.read(bb);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1363
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1364
39050
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1365
    // The requires table for java.base must be 0 length
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1366
    @Test(expectedExceptions = InvalidModuleDescriptorException.class)
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1367
    public void testReadOfJavaBaseWithRequires() {
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1368
        ModuleDescriptor descriptor
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1369
            = ModuleDescriptor.newModule("java.base")
39050
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1370
                .requires("other")
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1371
                .build();
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1372
        ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1373
        ModuleDescriptor.read(bb);
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1374
    }
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1375
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1376
    // The requires table must have an entry for java.base
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1377
    @Test(expectedExceptions = InvalidModuleDescriptorException.class)
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1378
    public void testReadWithEmptyRequires() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1379
        ModuleDescriptor descriptor = SharedSecrets.getJavaLangModuleAccess()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1380
                .newModuleBuilder("m1", false, Set.of()).build();
39050
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1381
        ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1382
        ModuleDescriptor.read(bb);
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1383
    }
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1384
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1385
    // The requires table must have an entry for java.base
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1386
    @Test(expectedExceptions = InvalidModuleDescriptorException.class)
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1387
    public void testReadWithNoRequiresBase() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1388
        ModuleDescriptor descriptor = SharedSecrets.getJavaLangModuleAccess()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1389
                .newModuleBuilder("m1", false, Set.of()).requires("m2").build();
39050
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1390
        ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1391
        ModuleDescriptor.read(bb);
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1392
    }
9de41b79ec7e 8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents: 36511
diff changeset
  1393
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1394
    public void testReadWithNull() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1395
        Module base = Object.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1396
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1397
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1398
            ModuleDescriptor.read((InputStream)null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1399
            assertTrue(false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1400
        } catch (NullPointerException expected) { }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1401
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1402
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1403
        try (InputStream in = base.getResourceAsStream("module-info.class")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1404
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1405
                ModuleDescriptor.read(in, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1406
                assertTrue(false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1407
            } catch (NullPointerException expected) { }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1408
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1409
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1410
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1411
            ModuleDescriptor.read((ByteBuffer)null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1412
            assertTrue(false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1413
        } catch (NullPointerException expected) { }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1414
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1415
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1416
        try (InputStream in = base.getResourceAsStream("module-info.class")) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1417
            ByteBuffer bb = ByteBuffer.wrap(in.readAllBytes());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1418
            try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1419
                ModuleDescriptor.read(bb, null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1420
                assertTrue(false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1421
            } catch (NullPointerException expected) { }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1422
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1423
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1424
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1425
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1426
    // equals/hashCode/compareTo/toString
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1427
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1428
    public void testEqualsAndHashCode() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1429
        ModuleDescriptor md1 = ModuleDescriptor.newModule("m").build();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1430
        ModuleDescriptor md2 = ModuleDescriptor.newModule("m").build();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1431
        assertEquals(md1, md1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1432
        assertEquals(md1.hashCode(), md2.hashCode());
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1433
        assertTrue(md1.compareTo(md2) == 0);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1434
        assertTrue(md2.compareTo(md1) == 0);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1435
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1436
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1437
    @DataProvider(name = "sortedModuleDescriptors")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1438
    public Object[][] sortedModuleDescriptors() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1439
        return new Object[][]{
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1440
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1441
            { ModuleDescriptor.newModule("m2").build(),
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1442
              ModuleDescriptor.newModule("m1").build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1443
            },
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1444
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1445
            { ModuleDescriptor.newModule("m").version("2").build(),
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1446
              ModuleDescriptor.newModule("m").version("1").build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1447
            },
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1448
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1449
            { ModuleDescriptor.newModule("m").version("1").build(),
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1450
              ModuleDescriptor.newModule("m").build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1451
            },
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1452
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1453
            { ModuleDescriptor.newOpenModule("m").build(),
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1454
              ModuleDescriptor.newModule("m").build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1455
            },
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1456
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1457
        };
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1458
    }
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1459
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1460
    @Test(dataProvider = "sortedModuleDescriptors")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1461
    public void testCompare(ModuleDescriptor md1, ModuleDescriptor md2) {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1462
        assertNotEquals(md1, md2);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1463
        assertTrue(md1.compareTo(md2) == 1);
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1464
        assertTrue(md2.compareTo(md1) == -1);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1465
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1466
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1467
    public void testToString() {
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1468
        String s = ModuleDescriptor.newModule("m1")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1469
                .requires("m2")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1470
                .exports("p1")
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1471
                .build()
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42703
diff changeset
  1472
                .toString();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1473
        assertTrue(s.contains("m1"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1474
        assertTrue(s.contains("m2"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1475
        assertTrue(s.contains("p1"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1476
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1477
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
  1478
}