Path: blob/master/test/jdk/java/lang/Class/getResource/ResourcesTest.java
41153 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.nio.file.Path;24import java.nio.file.Paths;2526import static jdk.test.lib.process.ProcessTools.executeTestJava;27import jdk.test.lib.compiler.CompilerUtils;2829import org.testng.annotations.BeforeTest;30import org.testng.annotations.Test;31import static org.testng.Assert.*;3233/**34* @test35* @library /test/lib36* @modules jdk.compiler37* @build ResourcesTest jdk.test.lib.compiler.CompilerUtils38* @run testng ResourcesTest39* @summary Driver for basic test of Class getResource and getResourceAsStream40*/4142@Test43public class ResourcesTest {4445private static final String TEST_SRC = System.getProperty("test.src");4647private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");48private static final Path CLASSES_DIR = Paths.get("classes");49private static final Path MODS_DIR = Paths.get("mods");505152/**53* Compiles the modules used by the test and the test Main54*/55@BeforeTest56public void compileAll() throws Exception {57boolean compiled;5859// javac -modulesource mods -d mods src/**60compiled = CompilerUtils61.compile(SRC_DIR,62MODS_DIR,63"--module-source-path", SRC_DIR.toString());64assertTrue(compiled);6566// javac --module-path mods -d classes Main.java67compiled = CompilerUtils68.compile(Paths.get(TEST_SRC, "Main.java"),69CLASSES_DIR,70"--module-path", MODS_DIR.toString(),71"--add-modules", "m1,m2");72assertTrue(compiled);7374}7576/**77* Run the test78*/79public void runTest() throws Exception {8081int exitValue82= executeTestJava("--module-path", MODS_DIR.toString(),83"--add-modules", "m1,m2",84"-cp", CLASSES_DIR.toString(),85"-Djava.security.manager=allow",86"Main")87.outputTo(System.out)88.errorTo(System.out)89.getExitValue();9091assertTrue(exitValue == 0);9293}9495}96979899