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.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertFalse;
21  import static org.junit.jupiter.api.Assertions.assertNotNull;
22  import static org.junit.jupiter.api.Assertions.assertTrue;
23  
24  import org.apache.commons.compress.harmony.pack200.Pack200Exception;
25  import org.junit.jupiter.api.Test;
26  
27  public class AttributeLayoutMapTest {
28  
29      @Test
30      public void testRepeatable() throws Pack200Exception {
31          // Check we can retrieve a default layout
32          final AttributeLayoutMap a = new AttributeLayoutMap();
33          AttributeLayout layout = a.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS);
34          assertNotNull(layout);
35          assertEquals("RUNH", layout.getLayout());
36          assertEquals(17, layout.getIndex());
37          // and that we can change it
38          a.add(new AttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS, "FROG", 17));
39          layout = a.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS);
40          assertNotNull(layout);
41          assertEquals("FROG", layout.getLayout());
42          assertTrue(layout.matches(1 << 17));
43          assertFalse(layout.matches(1 << 16));
44          assertTrue(layout.matches(-1));
45          assertFalse(layout.matches(0));
46          // and that changes don't affect subsequent defaults
47          final AttributeLayoutMap b = new AttributeLayoutMap();
48          layout = b.getAttributeLayout("SourceFile", AttributeLayout.CONTEXT_CLASS);
49          assertNotNull(layout);
50          assertEquals("RUNH", layout.getLayout());
51  
52      }
53  }