Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/invoke/MethodHandlesProxiesTest.java
47216 views
/*1* Copyright (c) 2018, 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/* @test24* @bug 820695525* @run testng/othervm -ea -esa test.java.lang.invoke.MethodHandlesProxiesTest26*/2728package test.java.lang.invoke;2930import org.testng.annotations.Test;3132import java.lang.invoke.MethodHandle;33import java.lang.invoke.MethodHandleProxies;34import java.lang.invoke.MethodHandles;3536import static org.testng.Assert.assertEquals;3738public class MethodHandlesProxiesTest {3940public interface A {41default String a() {42return "A";43}44}4546public interface B {47default String b() {48return "B";49}50}5152public interface C extends A, B {53String f();5455default String c() {56return "C";57}5859default String concat() {60return a() + b() + c();61}62}6364public interface Override extends C {65String f();6667default String a() {68return "OA";69}7071default String b() {72return "OB";73}7475default String c() {76return "OC";77}78}7980@Test81public static void testDefaultMethods() throws Throwable {82MethodHandle target = MethodHandles.constant(String.class, "F");83C proxy = MethodHandleProxies.asInterfaceInstance(C.class, target);8485assertEquals(proxy.f(), "F");86assertEquals(proxy.a(), "A");87assertEquals(proxy.b(), "B");88assertEquals(proxy.c(), "C");89assertEquals(proxy.concat(), "ABC");90}9192@Test93public static void testOverriddenDefaultMethods() throws Throwable {94MethodHandle target = MethodHandles.constant(String.class, "F");95Override proxy = MethodHandleProxies.asInterfaceInstance(Override.class, target);9697assertEquals(proxy.a(), "OA");98assertEquals(proxy.b(), "OB");99assertEquals(proxy.c(), "OC");100}101}102103104