briangoetz | ef42f9a | 2013-05-06 11:43:51 -0400 | [diff] [blame] | 1 | /* |
lana | f3d11f6 | 2013-12-26 12:04:16 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
briangoetz | ef42f9a | 2013-05-06 11:43:51 -0400 | [diff] [blame] | 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 | import org.testng.annotations.Test; |
| 25 | |
| 26 | import static org.testng.Assert.assertEquals; |
| 27 | |
| 28 | /** |
| 29 | * @author Robert Field |
| 30 | */ |
| 31 | |
| 32 | @Test |
| 33 | public class MethodReferenceTestNewInner { |
| 34 | |
| 35 | String note = "NO NOTE"; |
| 36 | |
| 37 | interface M0<T> { |
| 38 | |
| 39 | T m(); |
| 40 | } |
| 41 | |
| 42 | interface MP<T> { |
| 43 | |
| 44 | T m(MethodReferenceTestNewInner m); |
| 45 | } |
| 46 | |
| 47 | class N0 { |
| 48 | |
| 49 | N0() { |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | interface M1<T> { |
| 54 | |
| 55 | T m(Integer a); |
| 56 | } |
| 57 | |
| 58 | class N1 { |
| 59 | |
| 60 | int i; |
| 61 | |
| 62 | N1(int i) { |
| 63 | this.i = i; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | interface M2<T> { |
| 68 | |
| 69 | T m(Integer n, String o); |
| 70 | } |
| 71 | |
| 72 | class N2 { |
| 73 | |
| 74 | Number n; |
| 75 | Object o; |
| 76 | |
| 77 | N2(Number n, Object o) { |
| 78 | this.n = n; |
| 79 | this.o = o; |
| 80 | } |
| 81 | |
| 82 | public String toString() { |
| 83 | return note + ":N2(" + n + "," + o + ")"; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | interface MV { |
| 88 | |
| 89 | NV m(Integer ai, int i); |
| 90 | } |
| 91 | |
| 92 | class NV { |
| 93 | |
| 94 | int i; |
| 95 | |
| 96 | NV(int... v) { |
| 97 | i = 0; |
| 98 | for (int x : v) { |
| 99 | i += x; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | public String toString() { |
| 104 | return note + ":NV(" + i + ")"; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /* unbound constructor case not supported anymore (dropped by EG) |
| 109 | public static void testConstructorReferenceP() { |
| 110 | MP<N0> q; |
| 111 | |
| 112 | q = N0::new; |
| 113 | assertEquals(q.m(new MethodReferenceTestNewInner()).getClass().getSimpleName(), "N0"); |
| 114 | } |
| 115 | */ |
| 116 | public void testConstructorReference0() { |
| 117 | M0<N0> q; |
| 118 | |
| 119 | q = N0::new; |
| 120 | assertEquals(q.m().getClass().getSimpleName(), "N0"); |
| 121 | } |
| 122 | |
| 123 | public void testConstructorReference1() { |
| 124 | M1<N1> q; |
| 125 | |
| 126 | q = N1::new; |
| 127 | assertEquals(q.m(14).getClass().getSimpleName(), "N1"); |
| 128 | } |
| 129 | |
| 130 | public void testConstructorReference2() { |
| 131 | M2<N2> q; |
| 132 | |
| 133 | note = "T2"; |
| 134 | q = N2::new; |
| 135 | assertEquals(q.m(7, "hi").toString(), "T2:N2(7,hi)"); |
| 136 | } |
| 137 | |
| 138 | /*** |
| 139 | public void testConstructorReferenceVarArgs() { |
| 140 | MV q; |
| 141 | |
| 142 | note = "TVA"; |
| 143 | q = NV::new; |
| 144 | assertEquals(q.m(5, 45).toString(), "TNV:NV(50)"); |
| 145 | } |
| 146 | ***/ |
| 147 | |
| 148 | } |
| 149 | |
| 150 | |