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 MethodReferenceTestInnerInstance { |
| 34 | |
| 35 | public void testMethodReferenceInnerInstance() { |
| 36 | cia().cib().testMethodReferenceInstance(); |
| 37 | } |
| 38 | |
| 39 | public void testMethodReferenceInnerExternal() { |
| 40 | cia().cib().testMethodReferenceExternal(); |
| 41 | } |
| 42 | |
| 43 | interface SI { |
| 44 | String m(Integer a); |
| 45 | } |
| 46 | |
| 47 | class CIA { |
| 48 | |
| 49 | String xI(Integer i) { |
| 50 | return "xI:" + i; |
| 51 | } |
| 52 | |
| 53 | public class CIB { |
| 54 | |
| 55 | public void testMethodReferenceInstance() { |
| 56 | SI q; |
| 57 | |
| 58 | q = CIA.this::xI; |
| 59 | assertEquals(q.m(55), "xI:55"); |
| 60 | } |
| 61 | |
| 62 | public void testMethodReferenceExternal() { |
| 63 | SI q; |
| 64 | |
| 65 | q = (new E())::xI; |
| 66 | assertEquals(q.m(77), "ExI:77"); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | CIB cib() { |
| 71 | return new CIB(); |
| 72 | } |
| 73 | |
| 74 | class E { |
| 75 | |
| 76 | String xI(Integer i) { |
| 77 | return "ExI:" + i; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | CIA cia() { |
| 84 | return new CIA(); |
| 85 | } |
| 86 | } |