Path: blob/master/test/jdk/java/lang/Class/getMethods/StarInheritance.java
41153 views
/*1* Copyright (c) 2002, 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 465469826* @summary Verify that expected methods are returned for star inheritance.27*/2829import java.lang.reflect.Method;30import java.util.Arrays;31import java.util.ArrayList;3233// D.m34interface A1 extends B1, C1 {}35interface B1 extends D1 {}36interface C1 extends D1 {}37interface D1 { void m(); }3839// A.m40interface A2 extends B2, C2 { void m(); }41interface B2 extends D2 {}42interface C2 extends D2 {}43interface D2 { void m(); }4445// B.m, C.m46interface A3 extends B3, C3 {}47interface B3 extends D3 { void m(); }48interface C3 extends D3 { void m(); }49interface D3 { void m() ; }5051// B.m52interface A4 extends B4, C4 {}53interface B4 extends D4 { void m(); }54interface C4 extends D4 {}55interface D4 { void m(); }5657public class StarInheritance {58private static int n = 1;5960private static void test(Method [] ma, ArrayList expect) {61System.out.println("Test " + n++);6263if (expect.size() != ma.length) {64System.err.println(" found methods: " + Arrays.asList(ma));65System.err.println(" expected locations: " + expect);66throw new RuntimeException("found = " + ma.length67+"; expected = " + expect.size());68}6970for (int i = 0; i < ma.length; i++) {71Method m = ma[i];72System.out.println(" " + m.toString());73int n;74if (m.getName().equals("m")75&& (n = expect.indexOf(m.getDeclaringClass())) != -1) {76expect.remove(n);77} else {78throw new RuntimeException("unable to locate method in class: "79+ m.getDeclaringClass());80}81}82}8384public static void main(String [] args) {85Class [] l1 = {D1.class};86test(A1.class.getMethods(), new ArrayList(Arrays.asList(l1)));8788Class [] l2 = {A2.class};89test(A2.class.getMethods(), new ArrayList(Arrays.asList(l2)));9091Class [] l3 = {B3.class, C3.class};92test(A3.class.getMethods(), new ArrayList(Arrays.asList(l3)));9394Class [] l4 = {B4.class};95test(A4.class.getMethods(), new ArrayList(Arrays.asList(l4)));96}97}9899100