Path: blob/master/test/jdk/java/beans/Statement/Test4530962.java
41149 views
/*1* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 453096226* @summary Tests method search using parameter classes in Statement27* @author Mark Davidson28*/2930import java.beans.Statement;3132/**33* Ambiguous method signature should throw an exception.34* Statement should execute the most specific method.35*/36public class Test4530962 {37public static void main(String[] args) throws Exception {38try {39test(new A(), new Y(), new Y());40throw new Error("exception expected");41}42catch (NoSuchMethodException exception) {43// should throw an exception44}45catch (Exception exception) {46throw new Error("unexpected exception", exception);47}48test(new B(), new Y(), new Y());49test(new C(), new Z(), new Z());50test(new D(), new Z(), new Z());51test(new E(), new Z(), new Z());52}5354private static void test(Object target, Object... params) throws Exception {55new Statement(target, "m", params).execute();56}5758/**59* All ambiguous method declarations should fail.60*/61public static class A {62public void m(X x1, X x2) {63throw new Error("A.m(X,X) should not be called");64}6566public void m(X x1, Y y2) {67throw new Error("A.m(X,Y) should not be called");68}6970public void m(Y y1, X x2) {71throw new Error("A.m(Y,X) should not be called");72}73}7475/**76* The most specific method in this case would be the second declaration.77*/78public static class B {79public void m(X x1, X x2) {80throw new Error("B.m(X,X) should not be called");81}8283public void m(X x1, Y y2) {84// expected: B.m(X,Y) should be called85}86}8788/**89* The most specific method in this case would be the first declaration.90*/91public static class C {92public void m(Y y1, Y y2) {93// expected: C.m(Y,Y) should be called94}9596public void m(X x1, X x2) {97throw new Error("C.m(X,X) should not be called");98}99}100101/**102* Same as the previous case but flip methods.103*/104public static class D {105public void m(X x1, X x2) {106throw new Error("D.m(X,X) should not be called");107}108109public void m(Y y1, Y y2) {110// expected: D.m(Y,Y) should be called111}112}113114/**115* The method should be called with (Z,Z).116*/117public static class E {118public void m(X x1, X x2) {119// expected: E.m(X,X) should be called120}121}122123public static class X {124}125126public static class Y extends X {127}128129public static class Z extends Y {130}131}132133134