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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * @test 26 * @bug 8003639 27 * @summary convert lambda testng tests to jtreg and add them 28 * @run testng MethodReferenceTestNewInner 29 */ 30 31import org.testng.annotations.Test; 32 33import static org.testng.Assert.assertEquals; 34 35/** 36 * @author Robert Field 37 */ 38 39@Test 40public class MethodReferenceTestNewInner { 41 42 String note = "NO NOTE"; 43 44 interface M0<T> { 45 46 T m(); 47 } 48 49 interface MP<T> { 50 51 T m(MethodReferenceTestNewInner m); 52 } 53 54 class N0 { 55 56 N0() { 57 } 58 } 59 60 interface M1<T> { 61 62 T m(Integer a); 63 } 64 65 class N1 { 66 67 int i; 68 69 N1(int i) { 70 this.i = i; 71 } 72 } 73 74 interface M2<T> { 75 76 T m(Integer n, String o); 77 } 78 79 class N2 { 80 81 Number n; 82 Object o; 83 84 N2(Number n, Object o) { 85 this.n = n; 86 this.o = o; 87 } 88 89 public String toString() { 90 return note + ":N2(" + n + "," + o + ")"; 91 } 92 } 93 94 interface MV { 95 96 NV m(Integer ai, int i); 97 } 98 99 class NV { 100 101 int i; 102 103 NV(int... v) { 104 i = 0; 105 for (int x : v) { 106 i += x; 107 } 108 } 109 110 public String toString() { 111 return note + ":NV(" + i + ")"; 112 } 113 } 114 115/* unbound constructor case not supported anymore (dropped by EG) 116 public static void testConstructorReferenceP() { 117 MP<N0> q; 118 119 q = N0::new; 120 assertEquals(q.m(new MethodReferenceTestNewInner()).getClass().getSimpleName(), "N0"); 121 } 122*/ 123 public void testConstructorReference0() { 124 M0<N0> q; 125 126 q = N0::new; 127 assertEquals(q.m().getClass().getSimpleName(), "N0"); 128 } 129 130 public void testConstructorReference1() { 131 M1<N1> q; 132 133 q = N1::new; 134 assertEquals(q.m(14).getClass().getSimpleName(), "N1"); 135 } 136 137 public void testConstructorReference2() { 138 M2<N2> q; 139 140 note = "T2"; 141 q = N2::new; 142 assertEquals(q.m(7, "hi").toString(), "T2:N2(7,hi)"); 143 } 144 145 /*** 146 public void testConstructorReferenceVarArgs() { 147 MV q; 148 149 note = "TVA"; 150 q = NV::new; 151 assertEquals(q.m(5, 45).toString(), "TNV:NV(50)"); 152 } 153 ***/ 154 155} 156