1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package org.apache.bcel.util; 20 21 import java.io.IOException; 22 import java.nio.file.Path; 23 import java.util.Collection; 24 import java.util.List; 25 26 import org.apache.bcel.generic.JdkGenericDumpTestCase; 27 import org.apache.commons.lang3.JavaVersion; 28 import org.apache.commons.lang3.SystemUtils; 29 import org.junit.Assert; 30 import org.junit.Assume; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.junit.runners.Parameterized; 34 import org.junit.runners.Parameterized.Parameters; 35 36 /** 37 * Tests {@link ModularRuntimeImage}. 38 */ 39 @RunWith(Parameterized.class) 40 public class ModularRuntimeImageTestCase { 41 42 @Parameters(name = "{0}") data()43 public static Collection<String> data() { 44 return JdkGenericDumpTestCase.data(); 45 } 46 47 private final String javaHome; 48 private final ModularRuntimeImage modularRuntimeImage; 49 ModularRuntimeImageTestCase(final String javaHome)50 public ModularRuntimeImageTestCase(final String javaHome) throws IOException { 51 this.javaHome = javaHome; 52 Assume.assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9)); 53 this.modularRuntimeImage = new ModularRuntimeImage(javaHome); 54 } 55 56 @Test testListJreModules()57 public void testListJreModules() throws IOException { 58 final List<Path> listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH); 59 Assert.assertFalse(listEntries.isEmpty()); 60 Assert.assertTrue(listEntries.toString().indexOf("/java.base") > -1); 61 } 62 63 @Test testListJreModule()64 public void testListJreModule() throws IOException { 65 final List<Path> listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH + "/java.base"); 66 Assert.assertFalse(listEntries.isEmpty()); 67 Assert.assertTrue(listEntries.toString().indexOf("/java.base") > -1); 68 } 69 70 @Test testListJreModulePackageDir()71 public void testListJreModulePackageDir() throws IOException { 72 final List<Path> listEntries = modularRuntimeImage 73 .list(ModularRuntimeImage.MODULES_PATH + "/java.base/java/lang"); 74 Assert.assertFalse(listEntries.isEmpty()); 75 Assert.assertTrue(listEntries.toString().indexOf("/java.base/java/lang/String.class") > -1); 76 } 77 78 @Test testListJrePackages()79 public void testListJrePackages() throws IOException { 80 final List<Path> listEntries = modularRuntimeImage.list(ModularRuntimeImage.PACKAGES_PATH); 81 Assert.assertFalse(listEntries.isEmpty()); 82 Assert.assertTrue(listEntries.toString().indexOf("java.lang") > -1); 83 } 84 } 85