jdk/test/java/lang/reflect/Module/BasicModuleTest.java
author alanb
Thu, 17 Mar 2016 19:04:16 +0000
changeset 36511 9d0388c6b336
child 42338 a60f280f803c
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, chris.hegarty@oracle.com, alexandr.scherbatiy@oracle.com, amy.lu@oracle.com, calvin.cheung@oracle.com, daniel.fuchs@oracle.com, erik.joelsson@oracle.com, harold.seigel@oracle.com, jaroslav.bachorik@oracle.com, jean-francois.denise@oracle.com, jan.lahoda@oracle.com, james.laskey@oracle.com, lois.foltan@oracle.com, miroslav.kos@oracle.com, huaming.li@oracle.com, sean.mullan@oracle.com, naoto.sato@oracle.com, masayoshi.okutsu@oracle.com, peter.levart@gmail.com, philip.race@oracle.com, claes.redestad@oracle.com, sergey.bylokhov@oracle.com, alexandre.iline@oracle.com, volker.simonis@gmail.com, staffan.larsen@oracle.com, stuart.marks@oracle.com, semyon.sadetsky@oracle.com, serguei.spitsyn@oracle.com, sundararajan.athijegannathan@oracle.com, valerie.peng@oracle.com, vincent.x.ryan@oracle.com, weijun.wang@oracle.com, yuri.nesterenko@oracle.com, yekaterina.kantserova@oracle.com, alexander.kulyakhtin@oracle.com, felix.yang@oracle.com, andrei.eremeev@oracle.com, frank.yuan@oracle.com, sergei.pikalev@oracle.com, sibabrata.sahoo@oracle.com, tiantian.du@oracle.com, sha.jiang@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
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
import java.lang.module.ModuleDescriptor.Exports;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.lang.module.ResolvedModule;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.lang.reflect.Layer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.lang.reflect.Module;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.function.Predicate;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.stream.Stream;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 * @summary Basic test of java.lang.reflect.Module
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 * @modules java.desktop java.xml
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 * @run testng BasicModuleTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
public class BasicModuleTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
     * Tests that the given module reads all modules in the boot Layer.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    private void testReadsAllBootModules(Module m) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
        Layer bootLayer = Layer.boot();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
        bootLayer.configuration()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
            .modules()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
            .stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
            .map(ResolvedModule::name)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
            .map(bootLayer::findModule)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
            .forEach(target -> assertTrue(m.canRead(target.get())));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
     * Returns {@code true} if the array contains the given object.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private <T> boolean contains(T[] array, T obj) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        return Stream.of(array).anyMatch(obj::equals);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
     * Returns a {@code Predicate} to test if a package is exported.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    private Predicate<Exports> doesExport(String pn) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        return e -> (e.source().equals(pn) && !e.isQualified());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    public void testThisModule() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
        Module thisModule = BasicModuleTest.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
        Module baseModule = Object.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
        assertFalse(thisModule.isNamed());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
        assertTrue(thisModule.getName() == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
        assertTrue(thisModule.getDescriptor() == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
        assertTrue(thisModule.getLayer() == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        assertTrue(thisModule.toString().startsWith("unnamed module "));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
        ClassLoader thisLoader = BasicModuleTest.class.getClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
        assertTrue(thisLoader == thisModule.getClassLoader());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
        assertTrue(thisLoader.getUnnamedModule() == thisModule);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        // unnamed modules read all other modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        ClassLoader cl;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        cl = ClassLoader.getPlatformClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        assertTrue(thisModule.canRead(cl.getUnnamedModule()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        cl = ClassLoader.getSystemClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
        assertTrue(thisModule.canRead(cl.getUnnamedModule()));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
        testReadsAllBootModules(thisModule);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
        // unnamed modules export all packages
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
        assertTrue(thisModule.isExported(""));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        assertTrue(thisModule.isExported("", thisModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
        assertTrue(thisModule.isExported("", baseModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
        assertTrue(thisModule.isExported("p"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
        assertTrue(thisModule.isExported("p", thisModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
        assertTrue(thisModule.isExported("p", baseModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
        // this test is in the unnamed package
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
        assertTrue(contains(thisModule.getPackages(), ""));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
    public void testUnnamedModules() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
        Module thisModule = BasicModuleTest.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
        Module baseModule = Object.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        ClassLoader loader1 = ClassLoader.getSystemClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        ClassLoader loader2 = loader1.getParent();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        Module m1 = loader1.getUnnamedModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        Module m2 = loader2.getUnnamedModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        assertTrue(m1 != m2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        assertFalse(m1.isNamed());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
        assertFalse(m2.isNamed());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
        assertTrue(m1.getLayer() == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        assertTrue(m2.getLayer() == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        assertTrue(m1.toString().startsWith("unnamed module "));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
        assertTrue(m2.toString().startsWith("unnamed module "));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
        // unnamed module reads all modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        assertTrue(m1.canRead(m2));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        assertTrue(m2.canRead(m1));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        testReadsAllBootModules(m1);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
        testReadsAllBootModules(m2);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
        assertTrue(m1.isExported(""));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        assertTrue(m1.isExported("", thisModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        assertTrue(m1.isExported("", baseModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        assertTrue(m1.isExported("p"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
        assertTrue(m1.isExported("p", thisModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        assertTrue(m1.isExported("p", baseModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
    }
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
    public void testBaseModule() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        Module base = Object.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        Module thisModule = BasicModuleTest.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
        // getName
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        assertTrue(base.getName().equals("java.base"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        // getDescriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
        assertTrue(base.getDescriptor().exports().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
                .anyMatch(doesExport("java.lang")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
        // getClassLoader
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
        assertTrue(base.getClassLoader() == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
        // getLayer
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
        assertTrue(base.getLayer() == Layer.boot());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
        // toString
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
        assertEquals(base.toString(), "module java.base");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        // getPackages
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        assertTrue(contains(base.getPackages(), "java.lang"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
        // canRead
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
        assertTrue(base.canRead(base));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
        // isExported
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
        assertTrue(base.isExported("java.lang"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
        assertTrue(base.isExported("java.lang", thisModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        assertFalse(base.isExported("java.wombat"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
        assertFalse(base.isExported("java.wombat", thisModule));
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
    @Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
    public void testDesktopModule() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
        Module desktop = java.awt.Component.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
        Module base = Object.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
        Module xml = javax.xml.XMLConstants.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
        Module thisModule = BasicModuleTest.class.getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
        // name
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
        assertTrue(desktop.getName().equals("java.desktop"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
        // descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
        assertTrue(desktop.getDescriptor().exports().stream()
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                   .anyMatch(doesExport("java.awt")));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        // getClassLoader
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
        assertTrue(desktop.getClassLoader() == null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
        // getLayer
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
        assertTrue(desktop.getLayer() == Layer.boot());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
        // toString
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
        assertEquals(desktop.toString(), "module java.desktop");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
        // getPackages
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
        assertTrue(contains(desktop.getPackages(), "java.awt"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        assertTrue(contains(desktop.getPackages(), "sun.awt"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
        // canRead
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
        assertTrue(desktop.canRead(base));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        assertTrue(desktop.canRead(xml));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
        // isExported
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        assertTrue(desktop.isExported("java.awt"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        assertTrue(desktop.isExported("java.awt", thisModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
        assertFalse(desktop.isExported("java.wombat"));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
        assertFalse(desktop.isExported("java.wombat", thisModule));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
    @Test(expectedExceptions = { NullPointerException.class })
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
    public void testIsExportedNull() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
        Module thisModule = this.getClass().getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
        thisModule.isExported(null, thisModule);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
    @Test(expectedExceptions = { NullPointerException.class })
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
    public void testIsExportedToNull() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
        Module thisModule = this.getClass().getModule();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
        thisModule.isExported("", null);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
}