1 /* 2 * Copyright (C) 2017 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 import java.lang.reflect.Method; 18 19 public class Main { 20 public static class Super {} 21 public static class Sub1 {} 22 public static class Sub2 {} 23 assertTrue(boolean result)24 public static void assertTrue(boolean result) { 25 if (!result) { 26 throw new Error("Expected true"); 27 } 28 } 29 assertFalse(boolean result)30 public static void assertFalse(boolean result) { 31 if (result) { 32 throw new Error("Expected false"); 33 } 34 } 35 assertInstanceOfSub1(Object result)36 public static void assertInstanceOfSub1(Object result) { 37 if (!(result instanceof Sub1)) { 38 throw new Error("Expected instance of Sub1"); 39 } 40 } 41 assertInstanceOfSub2(Object result)42 public static void assertInstanceOfSub2(Object result) { 43 if (!(result instanceof Sub2)) { 44 throw new Error("Expected instance of Sub2"); 45 } 46 } 47 main(String[] args)48 public static void main(String[] args) throws Throwable { 49 Class<?> c = Class.forName("TestCase"); 50 Method m = c.getMethod("testCase", boolean.class); 51 Method m2 = c.getMethod("referenceTypeTestCase", Sub1.class, Sub2.class, boolean.class); 52 53 try { 54 assertTrue((Boolean) m.invoke(null, true)); 55 assertFalse((Boolean) m.invoke(null, false)); 56 assertInstanceOfSub1(m2.invoke(null, new Sub1(), new Sub2(), true)); 57 assertInstanceOfSub2(m2.invoke(null, new Sub1(), new Sub2(), false)); 58 } catch (Exception e) { 59 throw new Error(e); 60 } 61 } 62 } 63