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.commons.compress.harmony.unpack200;
21  
22  import static org.junit.jupiter.api.Assertions.assertEquals;
23  
24  import java.util.stream.Stream;
25  
26  import org.junit.jupiter.params.ParameterizedTest;
27  import org.junit.jupiter.params.provider.Arguments;
28  import org.junit.jupiter.params.provider.MethodSource;
29  
30  class ICTupleTest {
31  
32      static Stream<Arguments> explicit() {
33          return Stream.of(Arguments.of("Foo$$2$Local", null, "$2$Local", "$2$Local", "Foo$$2"),
34                  Arguments.of("Red$Herring", "Red$Herring", null, "Herring", "Red$Herring"), Arguments.of("X$1$Q", "X$1", "Q", "Q", "X$1"));
35      }
36  
37      static Stream<Arguments> predicted() {
38          return Stream.of(Arguments.of("orw/SimpleHelloWorld$SimpleHelloWorldInner", "SimpleHelloWorldInner", "orw/SimpleHelloWorld"),
39                  Arguments.of("java/util/AbstractList$2$Local", "Local", "java/util/AbstractList$2"),
40                  Arguments.of("java/util/AbstractList#2#Local", "Local", "java/util/AbstractList$2"),
41                  Arguments.of("java/util/AbstractList$1", "1", "java/util/AbstractList"));
42      }
43  
44      @ParameterizedTest
45      @MethodSource("explicit")
46      void testExplicitClassTupleParsing(final String c, final String c2, final String n, final String expectedSimpleClassName,
47              final String expectedOuterClass) {
48          final IcTuple tuple = new IcTuple(c, IcTuple.NESTED_CLASS_FLAG, c2, n, -1, -1, -1, -1);
49          assertEquals(expectedSimpleClassName, tuple.simpleClassName());
50          assertEquals(expectedOuterClass, tuple.outerClassString());
51      }
52  
53      @ParameterizedTest
54      @MethodSource("predicted")
55      void testPredictedClassTupleParsing(final String c, final String expectedSimpleClass, final String expectedOuterClass) {
56          final IcTuple tuple = new IcTuple(c, 0, null, null, -1, -1, -1, -1);
57          assertEquals(expectedSimpleClass, tuple.simpleClassName());
58          assertEquals(expectedOuterClass, tuple.outerClassString());
59      }
60  }