|
1 /* |
|
2 * Copyright (c) 2012 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 /** |
|
27 * @test |
|
28 * @bug 8003639 |
|
29 * @summary convert lambda testng tests to jtreg and add them |
|
30 * @run testng MethodReferenceTestKinds |
|
31 */ |
|
32 |
|
33 import org.testng.annotations.Test; |
|
34 |
|
35 import static org.testng.Assert.assertEquals; |
|
36 |
|
37 /** |
|
38 * @author Robert Field |
|
39 */ |
|
40 |
|
41 @Test |
|
42 public class MethodReferenceTestKinds extends MethodReferenceTestKindsSup { |
|
43 |
|
44 interface S0 { String get(); } |
|
45 interface S1 { String get(MethodReferenceTestKinds x); } |
|
46 interface S2 { String get(MethodReferenceTestKinds x, MethodReferenceTestKinds y); } |
|
47 |
|
48 interface SXN0 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x); } |
|
49 interface SXN1 { MethodReferenceTestKindsBase make(MethodReferenceTestKinds x, String str); } |
|
50 |
|
51 interface SN0 { MethodReferenceTestKindsBase make(); } |
|
52 interface SN1 { MethodReferenceTestKindsBase make(String x); } |
|
53 |
|
54 class In extends MethodReferenceTestKindsBase { |
|
55 In(String val) { |
|
56 this.val = val; |
|
57 } |
|
58 |
|
59 In() { |
|
60 this("blank"); |
|
61 } |
|
62 } |
|
63 |
|
64 String instanceMethod0() { return "IM:0-" + this; } |
|
65 String instanceMethod1(MethodReferenceTestKinds x) { return "IM:1-" + this + x; } |
|
66 |
|
67 static String staticMethod0() { return "SM:0"; } |
|
68 static String staticMethod1(MethodReferenceTestKinds x) { return "SM:1-" + x; } |
|
69 |
|
70 MethodReferenceTestKinds(String val) { |
|
71 super(val); |
|
72 } |
|
73 |
|
74 MethodReferenceTestKinds() { |
|
75 super("blank"); |
|
76 } |
|
77 |
|
78 MethodReferenceTestKinds inst(String val) { |
|
79 return new MethodReferenceTestKinds(val); |
|
80 } |
|
81 |
|
82 public void testMRBound() { |
|
83 S0 var = this::instanceMethod0; |
|
84 assertEquals(var.get(), "IM:0-MethodReferenceTestKinds(blank)"); |
|
85 } |
|
86 |
|
87 public void testMRBoundArg() { |
|
88 S1 var = this::instanceMethod1; |
|
89 assertEquals(var.get(inst("arg")), "IM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)"); |
|
90 } |
|
91 |
|
92 public void testMRUnbound() { |
|
93 S1 var = MethodReferenceTestKinds::instanceMethod0; |
|
94 assertEquals(var.get(inst("rcvr")), "IM:0-MethodReferenceTestKinds(rcvr)"); |
|
95 } |
|
96 |
|
97 public void testMRUnboundArg() { |
|
98 S2 var = MethodReferenceTestKinds::instanceMethod1; |
|
99 assertEquals(var.get(inst("rcvr"), inst("arg")), "IM:1-MethodReferenceTestKinds(rcvr)MethodReferenceTestKinds(arg)"); |
|
100 } |
|
101 |
|
102 public void testMRSuper() { |
|
103 S0 var = super::instanceMethod0; |
|
104 assertEquals(var.get(), "SIM:0-MethodReferenceTestKinds(blank)"); |
|
105 } |
|
106 |
|
107 public void testMRSuperArg() { |
|
108 S1 var = super::instanceMethod1; |
|
109 assertEquals(var.get(inst("arg")), "SIM:1-MethodReferenceTestKinds(blank)MethodReferenceTestKinds(arg)"); |
|
110 } |
|
111 |
|
112 public void testMRStatic() { |
|
113 S0 var = MethodReferenceTestKinds::staticMethod0; |
|
114 assertEquals(var.get(), "SM:0"); |
|
115 } |
|
116 |
|
117 public void testMRStaticArg() { |
|
118 S1 var = MethodReferenceTestKinds::staticMethod1; |
|
119 assertEquals(var.get(inst("arg")), "SM:1-MethodReferenceTestKinds(arg)"); |
|
120 } |
|
121 |
|
122 public void testMRStaticEval() { |
|
123 MethodReferenceTestKinds evalCheck; |
|
124 S0 var = (evalCheck = inst("discard"))::staticMethod0; |
|
125 assertEquals(evalCheck.toString(), "MethodReferenceTestKinds(discard)"); |
|
126 assertEquals(var.get(), "SM:0"); |
|
127 } |
|
128 |
|
129 public void testMRStaticEvalArg() { |
|
130 MethodReferenceTestKinds evalCheck; |
|
131 S1 var = (evalCheck = inst("discard"))::staticMethod1; |
|
132 assertEquals(evalCheck.toString(), "MethodReferenceTestKinds(discard)"); |
|
133 assertEquals(var.get(inst("arg")), "SM:1-MethodReferenceTestKinds(arg)"); |
|
134 } |
|
135 |
|
136 public void testMRTopLevel() { |
|
137 SN0 var = MethodReferenceTestKindsBase::new; |
|
138 assertEquals(var.make().toString(), "MethodReferenceTestKindsBase(blank)"); |
|
139 } |
|
140 |
|
141 public void testMRTopLevelArg() { |
|
142 SN1 var = MethodReferenceTestKindsBase::new; |
|
143 assertEquals(var.make("name").toString(), "MethodReferenceTestKindsBase(name)"); |
|
144 } |
|
145 /* unbound inner case not supported anymore (dropped by EG) |
|
146 public void testMRUnboundInner() { |
|
147 SXN0 var = MethodReferenceTestKinds.In::new; |
|
148 assertEquals(var.make(inst("out")).toString(), "In(blank)"); |
|
149 } |
|
150 |
|
151 public void testMRUnboundInnerArg() { |
|
152 SXN1 var = MethodReferenceTestKinds.In::new; |
|
153 assertEquals(var.make(inst("out"), "name").toString(), "In(name)"); |
|
154 } |
|
155 */ |
|
156 public void testMRImplicitInner() { |
|
157 SN0 var = MethodReferenceTestKinds.In::new; |
|
158 assertEquals(var.make().toString(), "In(blank)"); |
|
159 } |
|
160 |
|
161 public void testMRImplicitInnerArg() { |
|
162 SN1 var = MethodReferenceTestKinds.In::new; |
|
163 assertEquals(var.make("name").toString(), "In(name)"); |
|
164 } |
|
165 |
|
166 } |
|
167 |
|
168 |
|
169 class MethodReferenceTestKindsBase { |
|
170 String val = "unset"; |
|
171 |
|
172 public String toString() { |
|
173 return getClass().getSimpleName() + "(" + val + ")"; |
|
174 } |
|
175 |
|
176 MethodReferenceTestKindsBase(String val) { |
|
177 this.val = val; |
|
178 } |
|
179 |
|
180 MethodReferenceTestKindsBase() { |
|
181 this("blank"); |
|
182 } |
|
183 |
|
184 } |
|
185 |
|
186 class MethodReferenceTestKindsSup extends MethodReferenceTestKindsBase { |
|
187 String instanceMethod0() { return "SIM:0-" + this; } |
|
188 String instanceMethod1(MethodReferenceTestKinds x) { return "SIM:1-" + this + x; } |
|
189 |
|
190 MethodReferenceTestKindsSup(String val) { |
|
191 super(val); |
|
192 } |
|
193 |
|
194 } |