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.verifier;
21  
22  import java.io.IOException;
23  
24  import org.apache.bcel.verifier.tests.TestReturn01Creator;
25  import org.apache.bcel.verifier.tests.TestReturn03BooleanCreator;
26  import org.apache.bcel.verifier.tests.TestReturn03ByteCreator;
27  import org.apache.bcel.verifier.tests.TestReturn03DoubleCreator;
28  import org.apache.bcel.verifier.tests.TestReturn03FloatCreator;
29  import org.apache.bcel.verifier.tests.TestReturn03IntCreator;
30  import org.apache.bcel.verifier.tests.TestReturn03LongCreator;
31  import org.apache.bcel.verifier.tests.TestReturn03ObjectCreator;
32  import org.apache.bcel.verifier.tests.TestReturn03UnknownCreator;
33  import org.junit.jupiter.api.Assertions;
34  import org.junit.jupiter.api.Test;
35  
36  class VerifierReturnTest extends AbstractVerifierTest {
37  
38      @Test
39      void testInvalidReturn() throws IOException, ClassNotFoundException {
40          new TestReturn01Creator().create();
41          assertVerifyRejected("TestReturn01", "Verification of a void method that returns an object must fail.");
42          new TestReturn03IntCreator().create();
43          assertVerifyRejected("TestReturn03Int", "Verification of an int method that returns null int must fail.");
44          new TestReturn03FloatCreator().create();
45          assertVerifyRejected("TestReturn03Float", "Verification of a int method that returns null float must fail.");
46          new TestReturn03DoubleCreator().create();
47          assertVerifyRejected("TestReturn03Double", "Verification of a int method that returns null double must fail.");
48          new TestReturn03LongCreator().create();
49          assertVerifyRejected("TestReturn03Long", "Verification of a int method that returns null long must fail.");
50          new TestReturn03ByteCreator().create();
51          assertVerifyRejected("TestReturn03Byte", "Verification of a int method that returns null byte must fail.");
52          new TestReturn03BooleanCreator().create();
53          assertVerifyRejected("TestReturn03Boolean", "Verification of a int method that returns null boolean must fail.");
54          new TestReturn03ObjectCreator().create();
55          assertVerifyRejected("TestReturn03Object", "Verification of a int method that returns null Object must fail.");
56          final TestReturn03UnknownCreator testReturn03UnknownCreator = new TestReturn03UnknownCreator();
57          Assertions.assertThrowsExactly(IllegalArgumentException.class, testReturn03UnknownCreator::create, "Invalid type <unknown object>");
58      }
59  
60      @Test
61      void testValidReturn() throws ClassNotFoundException {
62          assertVerifyOK("TestReturn02", "Verification of a method that returns a newly created object must pass.");
63          assertVerifyOK("TestArray01", "Verification of a method that returns an array must pass.");
64      }
65  }