View Javadoc
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  package org.apache.bcel.util;
19  
20  import static org.junit.jupiter.api.Assertions.assertFalse;
21  import static org.junit.jupiter.api.Assertions.assertTrue;
22  import static org.junit.jupiter.api.Assumptions.assumeTrue;
23  
24  import java.io.IOException;
25  import java.nio.file.Path;
26  import java.util.List;
27  
28  import org.apache.commons.lang3.JavaVersion;
29  import org.apache.commons.lang3.SystemUtils;
30  import org.junit.jupiter.api.BeforeAll;
31  import org.junit.jupiter.params.ParameterizedTest;
32  import org.junit.jupiter.params.provider.MethodSource;
33  
34  /**
35   * Tests {@link ModularRuntimeImage}.
36   */
37  public class ModularRuntimeImageTestCase {
38  
39      @BeforeAll
40      public static void before() {
41          assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9));
42      }
43  
44      @ParameterizedTest
45      @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
46      public void testListJreModule(final ModularRuntimeImage modularRuntimeImage) throws IOException {
47          final List<Path> listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH + "/java.base");
48          assertFalse(listEntries.isEmpty());
49          assertTrue(listEntries.toString().indexOf("/java.base") > -1);
50      }
51  
52      @ParameterizedTest
53      @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
54      public void testListJreModulePackageDir(final ModularRuntimeImage modularRuntimeImage) throws IOException {
55          final List<Path> listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH + "/java.base/java/lang");
56          assertFalse(listEntries.isEmpty());
57          assertTrue(listEntries.toString().indexOf("/java.base/java/lang/String.class") > -1);
58      }
59  
60      @ParameterizedTest
61      @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
62      public void testListJreModules(final ModularRuntimeImage modularRuntimeImage) throws IOException {
63          final List<Path> listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH);
64          assertFalse(listEntries.isEmpty());
65          assertTrue(listEntries.toString().indexOf("/java.base") > -1);
66      }
67  
68      @ParameterizedTest
69      @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
70      public void testListJrePackages(final ModularRuntimeImage modularRuntimeImage) throws IOException {
71          final List<Path> listEntries = modularRuntimeImage.list(ModularRuntimeImage.PACKAGES_PATH);
72          assertFalse(listEntries.isEmpty());
73          assertTrue(listEntries.toString().indexOf("java.lang") > -1);
74      }
75  }