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  
18  package org.apache.bcel.generic;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  
22  import org.junit.jupiter.api.Test;
23  
24  public class ArrayTypeTest {
25  
26      @Test
27      public void testGetBasicType() {
28          final BasicType type = Type.BYTE;
29          final ArrayType objectType = new ArrayType(type, 1);
30          assertEquals(type, objectType.getBasicType());
31      }
32  
33      @Test
34      public void testGetClassName() {
35          final ArrayType objectType = new ArrayType(Type.BYTE, 1);
36          assertEquals("[B", objectType.getClassName());
37          assertEquals(byte[].class.getName(), objectType.getClassName());
38      }
39  
40      @Test
41      public void testGetDimensions() {
42          final int dimensions = 1;
43          final ArrayType objectType = new ArrayType(Type.BYTE, dimensions);
44          assertEquals(dimensions, objectType.getDimensions());
45      }
46  
47      @Test
48      public void testGetElementType() {
49          final BasicType type = Type.BYTE;
50          final ArrayType objectType = new ArrayType(Type.BYTE, 1);
51          assertEquals(type, objectType.getElementType());
52      }
53  
54      @Test
55      public void testGetSignatureDim1() {
56          final ArrayType objectType = new ArrayType(Type.BYTE, 1);
57          assertEquals("[B", objectType.getSignature());
58          assertEquals(byte[].class.getName(), objectType.getSignature());
59      }
60  
61      @Test
62      public void testGetSignatureDim2() {
63          final ArrayType objectType = new ArrayType(Type.BYTE, 2);
64          assertEquals("[[B", objectType.getSignature());
65          assertEquals(byte[][].class.getName(), objectType.getSignature());
66      }
67  
68      @Test
69      public void testGetSignatureDim4() {
70          final ArrayType objectType = new ArrayType(Type.BYTE, 4);
71          assertEquals("[[[[B", objectType.getSignature());
72          assertEquals(byte[][][][].class.getName(), objectType.getSignature());
73      }
74  
75      @Test
76      public void testGetSize() {
77          final ArrayType objectType = new ArrayType(Type.BYTE, 1);
78          assertEquals(1, objectType.getSize());
79      }
80  
81      @Test
82      public void testGetType() {
83          final ArrayType objectType = new ArrayType(Type.BYTE, 1);
84          assertEquals(13, objectType.getType());
85      }
86  
87  }