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