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  package org.apache.commons.compress.harmony.unpack200;
20  
21  import static org.junit.jupiter.api.Assertions.fail;
22  
23  import org.apache.commons.compress.harmony.pack200.Pack200Exception;
24  
25  /**
26   */
27  public abstract class AbstractBandsTest {
28  
29      public class MockAttributeDefinitionBands extends AttrDefinitionBands {
30  
31          public MockAttributeDefinitionBands(final Segment segment) {
32              super(segment);
33          }
34  
35          @Override
36          public AttributeLayoutMap getAttributeDefinitionMap() {
37              try {
38                  return new AttributeLayoutMap();
39              } catch (final Pack200Exception e) {
40                  fail(e.getLocalizedMessage());
41              }
42              return null;
43          }
44  
45      }
46  
47      public class MockSegment extends Segment {
48  
49          @Override
50          protected AttrDefinitionBands getAttrDefinitionBands() {
51              return new MockAttributeDefinitionBands(this);
52          }
53  
54          @Override
55          public SegmentHeader getSegmentHeader() {
56              return new MockSegmentHeader(this);
57          }
58      }
59  
60      public class MockSegmentHeader extends SegmentHeader {
61  
62          public MockSegmentHeader(final Segment segment) {
63              super(segment);
64          }
65  
66          @Override
67          public int getClassCount() {
68              return numClasses;
69          }
70  
71          @Override
72          public SegmentOptions getOptions() {
73              try {
74                  return new SegmentOptions(0);
75              } catch (final Pack200Exception e) {
76                  return null;
77              }
78          }
79      }
80  
81      protected int numClasses = 1;
82  
83      protected int[] numMethods = { 1 };
84  
85  }