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.bcel;
21  
22  import static org.junit.jupiter.api.Assertions.assertArrayEquals;
23  import static org.junit.jupiter.api.Assertions.assertEquals;
24  
25  import java.io.ByteArrayOutputStream;
26  import java.io.DataOutputStream;
27  import java.io.IOException;
28  
29  import org.apache.bcel.classfile.AnnotationEntry;
30  import org.apache.bcel.classfile.ElementValuePair;
31  import org.apache.bcel.classfile.SimpleElementValue;
32  import org.junit.jupiter.api.Test;
33  
34  /**
35   * Tests {@link AnnotationEntry}.
36   */
37  class AnnotationEntryTest {
38  
39      @Test
40      void testAddElementNameValuePair() {
41          final AnnotationEntry annotationEntry = new AnnotationEntry(0, null, false);
42          annotationEntry.addElementNameValuePair(new ElementValuePair(0, new SimpleElementValue(0, 0, null), null));
43          assertEquals(1, annotationEntry.getNumElementValuePairs());
44      }
45  
46      @Test
47      void testDump() throws IOException {
48          final ByteArrayOutputStream out = new ByteArrayOutputStream();
49          new AnnotationEntry(0, null, false).dump(new DataOutputStream(out));
50          assertArrayEquals(new byte[4], out.toByteArray());
51      }
52  
53      @Test
54      void testGetElementValuePairs() {
55          assertEquals(0, new AnnotationEntry(0, null, false).getElementValuePairs().length);
56      }
57  
58      @Test
59      void testGetNumElementValuePairs() {
60          assertEquals(0, new AnnotationEntry(0, null, false).getNumElementValuePairs());
61      }
62  }