Path: blob/master/test/jdk/java/lang/constant/DynamicCallSiteDescTest.java
66644 views
/*1* Copyright (c) 2021, 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*/2223import java.lang.invoke.MethodType;24import java.lang.constant.*;25import java.util.Arrays;26import java.util.List;27import java.util.stream.IntStream;28import java.util.stream.Stream;2930import org.testng.annotations.Test;3132import static java.lang.constant.ConstantDescs.CD_int;33import static java.lang.constant.ConstantDescs.CD_void;34import static java.util.stream.Collectors.joining;35import static java.util.stream.Collectors.toList;36import static org.testng.Assert.assertEquals;37import static org.testng.Assert.fail;3839/**40* @test41* @compile DynamicCallSiteDescTest.java42* @run testng DynamicCallSiteDescTest43* @summary unit tests for java.lang.constant.DynamicCallSiteDesc44*/4546@Test47public class DynamicCallSiteDescTest extends SymbolicDescTest {48/* note there is no unit test for method resolveCallSiteDesc as it is being tested in another test in this49* suite, IndyDescTest50*/5152public void testOf() throws ReflectiveOperationException {53DirectMethodHandleDesc dmh = ConstantDescs.ofCallsiteBootstrap(54ClassDesc.of("BootstrapAndTarget"),55"bootstrap",56ClassDesc.of("java.lang.invoke.CallSite")57);58try {59DynamicCallSiteDesc.of(60dmh,61"",62MethodTypeDesc.ofDescriptor("()I")63);64fail("IllegalArgumentException expected");65} catch (IllegalArgumentException iae) {66// good67}6869try {70DynamicCallSiteDesc.of(71null,72"getTarget",73MethodTypeDesc.ofDescriptor("()I")74);75fail("NullPointerException expected");76} catch (NullPointerException npe) {77// good78}7980try {81DynamicCallSiteDesc.of(82dmh,83null,84MethodTypeDesc.ofDescriptor("()I")85);86fail("NullPointerException expected");87} catch (NullPointerException npe) {88// good89}9091try {92DynamicCallSiteDesc.of(93dmh,94"getTarget",95null96);97fail("NullPointerException expected");98} catch (NullPointerException npe) {99// good100}101102try {103DynamicCallSiteDesc.of(104dmh,105"getTarget",106MethodTypeDesc.ofDescriptor("()I"),107null108);109fail("NullPointerException expected");110} catch (NullPointerException npe) {111// good112}113try {114DynamicCallSiteDesc.of(115dmh,116"getTarget",117MethodTypeDesc.ofDescriptor("()I"),118new ConstantDesc[]{ null }119);120fail("NullPointerException expected");121} catch (NullPointerException npe) {122// good123}124}125126public void testWithArgs() throws ReflectiveOperationException {127DynamicCallSiteDesc desc = DynamicCallSiteDesc.of(ConstantDescs.ofCallsiteBootstrap(128ClassDesc.of("BootstrapAndTarget"),129"bootstrap",130ClassDesc.of("java.lang.invoke.CallSite")131),132"getTarget",133MethodTypeDesc.ofDescriptor("()I")134);135136try {137desc.withArgs(null);138fail("NullPointerException expected");139} catch (NullPointerException npe) {140// good141}142143try {144desc.withArgs(new ConstantDesc[]{ null });145fail("NullPointerException expected");146} catch (NullPointerException npe) {147// good148}149}150151public void testWithNameAndType() throws ReflectiveOperationException {152DynamicCallSiteDesc desc = DynamicCallSiteDesc.of(ConstantDescs.ofCallsiteBootstrap(153ClassDesc.of("BootstrapAndTarget"),154"bootstrap",155ClassDesc.of("java.lang.invoke.CallSite")156),157"getTarget",158MethodTypeDesc.ofDescriptor("()I")159);160161try {162desc.withNameAndType(null, MethodTypeDesc.ofDescriptor("()I"));163fail("NullPointerException expected");164} catch (NullPointerException npe) {165// good166}167168try {169desc.withNameAndType("bootstrap", null);170fail("NullPointerException expected");171} catch (NullPointerException npe) {172// good173}174}175176public void testAccessorsAndFactories() throws ReflectiveOperationException {177DynamicCallSiteDesc desc = DynamicCallSiteDesc.of(ConstantDescs.ofCallsiteBootstrap(178ClassDesc.of("BootstrapAndTarget"),179"bootstrap",180ClassDesc.of("java.lang.invoke.CallSite")181),182"_",183MethodTypeDesc.ofDescriptor("()I")184);185assertEquals(desc, DynamicCallSiteDesc.of((DirectMethodHandleDesc)desc.bootstrapMethod(), desc.invocationType()));186assertEquals(desc, DynamicCallSiteDesc.of((DirectMethodHandleDesc)desc.bootstrapMethod(),187desc.invocationName(), desc.invocationType()));188assertEquals(desc, DynamicCallSiteDesc.of((DirectMethodHandleDesc)desc.bootstrapMethod(),189desc.invocationName(), desc.invocationType(), desc.bootstrapArgs()));190}191}192193194