1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang.constant; 27 28 import java.lang.invoke.*; 29 import java.lang.constant.*; 30 import java.util.*; 31 32 import org.testng.annotations.Test; 33 34 import static org.testng.Assert.*; 35 36 /** 37 * @test 38 * @compile ConstantUtilsTest.java 39 * @run testng ConstantUtilsTest 40 * @summary unit tests for methods of java.lang.constant.ConstantUtils that are not covered by other unit tests 41 */ 42 @Test 43 public class ConstantUtilsTest { 44 private static ClassDesc thisClass = ClassDesc.of("MethodHandleRefTest"); 45 46 public void testValidateMemberName() { 47 try { 48 ConstantUtils.validateMemberName(null); 49 fail(""); 50 } catch (NullPointerException e) { 51 // good 52 } 53 54 try { 55 ConstantUtils.validateMemberName(""); 56 fail(""); 57 } catch (IllegalArgumentException e) { 58 // good 59 } 60 61 List<String> badNames = List.of(".", ";", "[", "/", "<", ">"); 62 for (String n : badNames) { 63 try { 64 ConstantUtils.validateMemberName(n); 65 fail(n); 66 } catch (IllegalArgumentException e) { 67 // good 68 } 69 } 70 } 71 72 public void testSymbolizeHelper() { 73 DirectMethodHandleDesc mh = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.VIRTUAL, ConstantDescs.CR_String, "isEmpty", "()Z"); 74 try { 75 ConstantUtils.symbolizeHelper(mh, null, ""); 76 fail(""); 77 } catch (NullPointerException e) { 78 // good 79 } 80 81 try { 82 ConstantUtils.symbolizeHelper(null, ConstantDescs.CR_ClassDesc, ""); 83 fail(""); 84 } catch (NullPointerException e) { 85 // good 86 } 87 88 try { 89 ConstantUtils.symbolizeHelper(null, null, ""); 90 fail(""); 91 } catch (NullPointerException e) { 92 // good 93 } 94 } 95 }