1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestKinds.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,170 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +/** 1.30 + * @test 1.31 + * @bug 8003639 1.32 + * @summary convert lambda testng tests to jtreg and add them 1.33 + * @run testng MethodReferenceTestKinds 1.34 + */ 1.35 + 1.36 +import org.testng.annotations.Test; 1.37 + 1.38 +import static org.testng.Assert.assertEquals; 1.39 + 1.40 +/** 1.41 + * @author Robert Field 1.42 + */ 1.43 + 1.44 +@Test 1.45 +public class MethodReferenceTestKinds extends MethodReferenceTestKindsSup { 1.46 + 1.47 + interface S0 { String get(); } 1.48 + interface S1 { String get(MethodReferenceTestKinds x); } 1.49 + interface S2 { String get(MethodReferenceTestKinds x, MethodReferenceTestKinds y); } 1.50 + 1.51 + interface SXN0 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x); } 1.52 + interface SXN1 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x, String str); } 1.53 + 1.54 + interface SN0 { MethodReferenceTestKindsBase make(); } 1.55 + interface SN1 { MethodReferenceTestKindsBase make(String x); } 1.56 + 1.57 + class In extends MethodReferenceTestKindsBase { 1.58 + In(String val) { 1.59 + this.val = val; 1.60 + } 1.61 + 1.62 + In() { 1.63 + this("blank"); 1.64 + } 1.65 + } 1.66 + 1.67 + String instanceMethod0() { return "IM:0-" + this; } 1.68 + String instanceMethod1(MethodReferenceTestKinds x) { return "IM:1-" + this + x; } 1.69 + 1.70 + static String staticMethod0() { return "SM:0"; } 1.71 + static String staticMethod1(MethodReferenceTestKinds x) { return "SM:1-" + x; } 1.72 + 1.73 + MethodReferenceTestKinds(String val) { 1.74 + super(val); 1.75 + } 1.76 + 1.77 + MethodReferenceTestKinds() { 1.78 + super("blank"); 1.79 + } 1.80 + 1.81 + MethodReferenceTestKinds inst(String val) { 1.82 + return new MethodReferenceTestKinds(val); 1.83 + } 1.84 + 1.85 + public void testMRBound() { 1.86 + S0 var = this::instanceMethod0; 1.87 + assertEquals(var.get(), "IM:0-MethodReferenceTestKinds(blank)"); 1.88 + } 1.89 + 1.90 + public void testMRBoundArg() { 1.91 + S1 var = this::instanceMethod1; 1.92 + assertEquals(var.get(inst("arg")), "IM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)"); 1.93 + } 1.94 + 1.95 + public void testMRUnbound() { 1.96 + S1 var = MethodReferenceTestKinds::instanceMethod0; 1.97 + assertEquals(var.get(inst("rcvr")), "IM:0-MethodReferenceTestKinds(rcvr)"); 1.98 + } 1.99 + 1.100 + public void testMRUnboundArg() { 1.101 + S2 var = MethodReferenceTestKinds::instanceMethod1; 1.102 + assertEquals(var.get(inst("rcvr"), inst("arg")), "IM:1-MethodReferenceTestKinds(rcvr)MethodReferenceTestKinds(arg)"); 1.103 + } 1.104 + 1.105 + public void testMRSuper() { 1.106 + S0 var = super::instanceMethod0; 1.107 + assertEquals(var.get(), "SIM:0-MethodReferenceTestKinds(blank)"); 1.108 + } 1.109 + 1.110 + public void testMRSuperArg() { 1.111 + S1 var = super::instanceMethod1; 1.112 + assertEquals(var.get(inst("arg")), "SIM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)"); 1.113 + } 1.114 + 1.115 + public void testMRStatic() { 1.116 + S0 var = MethodReferenceTestKinds::staticMethod0; 1.117 + assertEquals(var.get(), "SM:0"); 1.118 + } 1.119 + 1.120 + public void testMRStaticArg() { 1.121 + S1 var = MethodReferenceTestKinds::staticMethod1; 1.122 + assertEquals(var.get(inst("arg")), "SM:1-MethodReferenceTestKinds(arg)"); 1.123 + } 1.124 + 1.125 + public void testMRTopLevel() { 1.126 + SN0 var = MethodReferenceTestKindsBase::new; 1.127 + assertEquals(var.make().toString(), "MethodReferenceTestKindsBase(blank)"); 1.128 + } 1.129 + 1.130 + public void testMRTopLevelArg() { 1.131 + SN1 var = MethodReferenceTestKindsBase::new; 1.132 + assertEquals(var.make("name").toString(), "MethodReferenceTestKindsBase(name)"); 1.133 + } 1.134 + 1.135 + public void testMRImplicitInner() { 1.136 + SN0 var = MethodReferenceTestKinds.In::new; 1.137 + assertEquals(var.make().toString(), "In(blank)"); 1.138 + } 1.139 + 1.140 + public void testMRImplicitInnerArg() { 1.141 + SN1 var = MethodReferenceTestKinds.In::new; 1.142 + assertEquals(var.make("name").toString(), "In(name)"); 1.143 + } 1.144 + 1.145 +} 1.146 + 1.147 + 1.148 +class MethodReferenceTestKindsBase { 1.149 + String val = "unset"; 1.150 + 1.151 + public String toString() { 1.152 + return getClass().getSimpleName() + "(" + val + ")"; 1.153 + } 1.154 + 1.155 + MethodReferenceTestKindsBase(String val) { 1.156 + this.val = val; 1.157 + } 1.158 + 1.159 + MethodReferenceTestKindsBase() { 1.160 + this("blank"); 1.161 + } 1.162 + 1.163 +} 1.164 + 1.165 +class MethodReferenceTestKindsSup extends MethodReferenceTestKindsBase { 1.166 + String instanceMethod0() { return "SIM:0-" + this; } 1.167 + String instanceMethod1(MethodReferenceTestKinds x) { return "SIM:1-" + this + x; } 1.168 + 1.169 + MethodReferenceTestKindsSup(String val) { 1.170 + super(val); 1.171 + } 1.172 + 1.173 +}