1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package libcore.java.lang.invoke; 18 19 import junit.framework.TestCase; 20 21 import java.lang.invoke.MethodHandleInfo; 22 import java.lang.invoke.MethodType; 23 24 import static java.lang.invoke.MethodHandleInfo.*; 25 26 public class MethodHandleInfoTest extends TestCase { 27 public void test_toString() { 28 final MethodType type = MethodType.methodType(String.class, String.class); 29 String string = MethodHandleInfo.toString(REF_invokeVirtual, String.class, "concat", type); 30 assertEquals("invokeVirtual java.lang.String.concat:(String)String", string); 31 32 try { 33 MethodHandleInfo.toString(-1, String.class, "concat", type); 34 fail(); 35 } catch (IllegalArgumentException expected) { 36 } 37 38 try { 39 MethodHandleInfo.toString(REF_invokeVirtual, String.class, null, type); 40 fail(); 41 } catch (NullPointerException expected) { 42 } 43 44 try { 45 MethodHandleInfo.toString(REF_invokeVirtual, null, "concat", type); 46 fail(); 47 } catch (NullPointerException expected) { 48 } 49 50 try { 51 MethodHandleInfo.toString(REF_invokeVirtual, String.class, "concat", null); 52 fail(); 53 } catch (NullPointerException expected) { 54 } 55 } 56 57 public void test_referenceKindToString() { 58 assertEquals("getField", referenceKindToString(REF_getField)); 59 assertEquals("getStatic", referenceKindToString(REF_getStatic)); 60 assertEquals("putField", referenceKindToString(REF_putField)); 61 assertEquals("putStatic", referenceKindToString(REF_putStatic)); 62 assertEquals("invokeVirtual", referenceKindToString(REF_invokeVirtual)); 63 assertEquals("invokeStatic", referenceKindToString(REF_invokeStatic)); 64 assertEquals("invokeSpecial", referenceKindToString(REF_invokeSpecial)); 65 assertEquals("newInvokeSpecial", referenceKindToString(REF_newInvokeSpecial)); 66 assertEquals("invokeInterface", referenceKindToString(REF_invokeInterface)); 67 68 try { 69 referenceKindToString(-1); 70 fail(); 71 } catch (IllegalArgumentException expected) { 72 } 73 74 try { 75 referenceKindToString(256); 76 fail(); 77 } catch (IllegalArgumentException expected) { 78 } 79 } 80 } 81