aoqi@0: /* aoqi@0: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * @test aoqi@0: * @bug 8003639 aoqi@0: * @summary convert lambda testng tests to jtreg and add them aoqi@0: * @run testng MethodReferenceTestVarArgsThis aoqi@0: */ aoqi@0: aoqi@0: import org.testng.annotations.Test; aoqi@0: import java.lang.reflect.Array; aoqi@0: aoqi@0: import static org.testng.Assert.assertEquals; aoqi@0: aoqi@0: /** aoqi@0: * @author Robert Field aoqi@0: */ aoqi@0: aoqi@0: interface NsII { String m(Integer a, Integer b); } aoqi@0: aoqi@0: interface Nsiii { String m(int a, int b, int c); } aoqi@0: aoqi@0: interface Nsi { String m(int a); } aoqi@0: aoqi@0: interface NsaO { String m(Object[] a); } aoqi@0: aoqi@0: interface Nsai { String m(int[] a); } aoqi@0: aoqi@0: interface Nsvi { String m(int... va); } aoqi@0: aoqi@0: @Test aoqi@0: public class MethodReferenceTestVarArgsThis { aoqi@0: aoqi@0: // These should be processed as var args aoqi@0: aoqi@0: String xvI(Integer... vi) { aoqi@0: StringBuilder sb = new StringBuilder("xvI:"); aoqi@0: for (Integer i : vi) { aoqi@0: sb.append(i); aoqi@0: sb.append("-"); aoqi@0: } aoqi@0: return sb.toString(); aoqi@0: } aoqi@0: aoqi@0: String xIvI(Integer f, Integer... vi) { aoqi@0: StringBuilder sb = new StringBuilder("xIvI:"); aoqi@0: sb.append(f); aoqi@0: for (Integer i : vi) { aoqi@0: sb.append(i); aoqi@0: sb.append("-"); aoqi@0: } aoqi@0: return sb.toString(); aoqi@0: } aoqi@0: aoqi@0: String xvi(int... vi) { aoqi@0: int sum = 0; aoqi@0: for (int i : vi) { aoqi@0: sum += i; aoqi@0: } aoqi@0: return "xvi:" + sum; aoqi@0: } aoqi@0: aoqi@0: String xIvi(Integer f, int... vi) { aoqi@0: int sum = 0; aoqi@0: for (int i : vi) { aoqi@0: sum += i; aoqi@0: } aoqi@0: return "xIvi:(" + f + ")" + sum; aoqi@0: } aoqi@0: aoqi@0: String xvO(Object... vi) { aoqi@0: StringBuilder sb = new StringBuilder("xvO:"); aoqi@0: for (Object i : vi) { aoqi@0: if (i.getClass().isArray()) { aoqi@0: sb.append("["); aoqi@0: int len = Array.getLength(i); aoqi@0: for (int x = 0; x < len; ++x) { aoqi@0: sb.append(Array.get(i, x)); aoqi@0: sb.append(","); aoqi@0: } aoqi@0: sb.append("]"); aoqi@0: aoqi@0: } else { aoqi@0: sb.append(i); aoqi@0: } aoqi@0: sb.append("*"); aoqi@0: } aoqi@0: return sb.toString(); aoqi@0: } aoqi@0: aoqi@0: public void testVarArgsNsSuperclass() { aoqi@0: NsII q; aoqi@0: aoqi@0: q = this::xvO; aoqi@0: assertEquals(q.m(55,66), "xvO:55*66*"); aoqi@0: } aoqi@0: aoqi@0: public void testVarArgsNsArray() { aoqi@0: Nsai q; aoqi@0: aoqi@0: q = this::xvO; aoqi@0: assertEquals(q.m(new int[] { 55,66 } ), "xvO:[55,66,]*"); aoqi@0: } aoqi@0: aoqi@0: public void testVarArgsNsII() { aoqi@0: NsII q; aoqi@0: aoqi@0: q = this::xvI; aoqi@0: assertEquals(q.m(33,7), "xvI:33-7-"); aoqi@0: aoqi@0: q = this::xIvI; aoqi@0: assertEquals(q.m(50,40), "xIvI:5040-"); aoqi@0: aoqi@0: q = this::xvi; aoqi@0: assertEquals(q.m(100,23), "xvi:123"); aoqi@0: aoqi@0: q = this::xIvi; aoqi@0: assertEquals(q.m(9,21), "xIvi:(9)21"); aoqi@0: } aoqi@0: aoqi@0: public void testVarArgsNsiii() { aoqi@0: Nsiii q; aoqi@0: aoqi@0: q = this::xvI; aoqi@0: assertEquals(q.m(3, 2, 1), "xvI:3-2-1-"); aoqi@0: aoqi@0: q = this::xIvI; aoqi@0: assertEquals(q.m(888, 99, 2), "xIvI:88899-2-"); aoqi@0: aoqi@0: q = this::xvi; aoqi@0: assertEquals(q.m(900,80,7), "xvi:987"); aoqi@0: aoqi@0: q = this::xIvi; aoqi@0: assertEquals(q.m(333,27, 72), "xIvi:(333)99"); aoqi@0: } aoqi@0: aoqi@0: public void testVarArgsNsi() { aoqi@0: Nsi q; aoqi@0: aoqi@0: q = this::xvI; aoqi@0: assertEquals(q.m(3), "xvI:3-"); aoqi@0: aoqi@0: q = this::xIvI; aoqi@0: assertEquals(q.m(888), "xIvI:888"); aoqi@0: aoqi@0: q = this::xvi; aoqi@0: assertEquals(q.m(900), "xvi:900"); aoqi@0: aoqi@0: q = this::xIvi; aoqi@0: assertEquals(q.m(333), "xIvi:(333)0"); aoqi@0: } aoqi@0: aoqi@0: // These should NOT be processed as var args aoqi@0: aoqi@0: public void testVarArgsNsaO() { aoqi@0: NsaO q; aoqi@0: aoqi@0: q = this::xvO; aoqi@0: assertEquals(q.m(new String[] { "yo", "there", "dude" }), "xvO:yo*there*dude*"); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: }