< prev index next >

test/jdk/java/lang/ClassLoader/getResource/GetResource.java

Print this page
rev 51638 : [mq]: 8210112


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6760902
  27  * @library /lib/testlibrary
  28  * @build jdk.testlibrary.ProcessTools

  29  * @run testng GetResource
  30  * @summary Empty path on bootclasspath is not default to current working
  31  *          directory for both class lookup and resource lookup whereas
  32  *          empty path on classpath is default to current working directory.
  33  */
  34 
  35 import java.io.File;
  36 import java.io.IOException;
  37 import java.net.URL;
  38 import java.nio.file.Files;
  39 import java.nio.file.Path;
  40 import java.nio.file.Paths;
  41 import java.util.ArrayList;
  42 import java.util.List;
  43 import java.util.Map;
  44 import java.util.stream.Collectors;
  45 import java.util.stream.Stream;
  46 
  47 import jdk.testlibrary.JDKToolFinder;
  48 import static jdk.testlibrary.ProcessTools.*;
  49 
  50 import org.testng.annotations.BeforeTest;
  51 import org.testng.annotations.DataProvider;
  52 import org.testng.annotations.Test;
  53 
  54 public class GetResource {
  55     private static final Path CWD = Paths.get(System.getProperty("user.dir"));
  56     private static final String DIR_A = "a";
  57     private static final String DIR_B = "b";
  58 
  59     private static final String RESOURCE_NAME = "test.properties";
  60     private static final String GETRESOURCE_CLASS = "GetResource.class";
  61 
  62     public static void main(String... args) {
  63         String expect = args[0] + "/" + RESOURCE_NAME;
  64         URL url = GetResource.class.getResource(RESOURCE_NAME);
  65         System.out.println("getResource found: " + url);
  66         if (!url.toString().endsWith(expect)) {
  67             throw new RuntimeException(url + " != expected resource " + expect);
  68         }




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6760902
  27  * @library /lib/testlibrary
  28  * @library /test/lib
  29  * @build jdk.test.lib.process.ProcessTools
  30  * @run testng GetResource
  31  * @summary Empty path on bootclasspath is not default to current working
  32  *          directory for both class lookup and resource lookup whereas
  33  *          empty path on classpath is default to current working directory.
  34  */
  35 
  36 import java.io.File;
  37 import java.io.IOException;
  38 import java.net.URL;
  39 import java.nio.file.Files;
  40 import java.nio.file.Path;
  41 import java.nio.file.Paths;
  42 import java.util.ArrayList;
  43 import java.util.List;
  44 import java.util.Map;
  45 import java.util.stream.Collectors;
  46 import java.util.stream.Stream;
  47 
  48 import jdk.testlibrary.JDKToolFinder;
  49 import static jdk.test.lib.process.ProcessTools.*;
  50 
  51 import org.testng.annotations.BeforeTest;
  52 import org.testng.annotations.DataProvider;
  53 import org.testng.annotations.Test;
  54 
  55 public class GetResource {
  56     private static final Path CWD = Paths.get(System.getProperty("user.dir"));
  57     private static final String DIR_A = "a";
  58     private static final String DIR_B = "b";
  59 
  60     private static final String RESOURCE_NAME = "test.properties";
  61     private static final String GETRESOURCE_CLASS = "GetResource.class";
  62 
  63     public static void main(String... args) {
  64         String expect = args[0] + "/" + RESOURCE_NAME;
  65         URL url = GetResource.class.getResource(RESOURCE_NAME);
  66         System.out.println("getResource found: " + url);
  67         if (!url.toString().endsWith(expect)) {
  68             throw new RuntimeException(url + " != expected resource " + expect);
  69         }


< prev index next >