Path: blob/master/test/jdk/java/lang/invoke/ConstantIdentityMHTest.java
41149 views
/*1* Copyright (c) 2016, 2019, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/* @test26* @summary unit tests for java.lang.invoke.MethodHandles27* @run testng/othervm -ea -esa test.java.lang.invoke.ConstantIdentityMHTest28*/29package test.java.lang.invoke;3031import java.lang.invoke.MethodHandle;32import java.lang.invoke.MethodHandles;33import static java.lang.invoke.MethodHandles.*;34import static java.lang.invoke.MethodType.*;35import static org.testng.Assert.*;36import org.testng.annotations.*;3738public class ConstantIdentityMHTest {3940@DataProvider(name = "testZeroData")41private Object[][] testZeroData() {42return new Object[][] {43{void.class, "()void"},44{int.class, "()int"},45{byte.class, "()byte"},46{short.class, "()short"},47{long.class, "()long"},48{float.class, "()float"},49{double.class, "()double"},50{boolean.class, "()boolean"},51{char.class, "()char"},52{Integer.class, "()Integer"}53};54}5556@Test(dataProvider = "testZeroData")57public void testZero(Class<?> expectedtype, String expected) throws Throwable {58assertEquals(MethodHandles.zero(expectedtype).type().toString(), expected);59}6061@Test(expectedExceptions={ NullPointerException.class })62public void testZeroNPE() {63MethodHandle mh = MethodHandles.zero(null);64}6566@Test67void testEmpty() throws Throwable {68MethodHandle cat = lookup().findVirtual(String.class, "concat", methodType(String.class, String.class));69assertEquals((String)cat.invoke("x","y"), "xy");70MethodHandle mhEmpty = MethodHandles.empty(cat.type());71assertEquals((String)mhEmpty.invoke("x","y"), null);72}7374@Test(expectedExceptions = { NullPointerException.class })75void testEmptyNPE() {76MethodHandle lenEmptyMH = MethodHandles.empty(null);77}78}798081