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