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