test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestNew.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceTestNew.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,138 @@
     1.4 +/*
     1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +/**
    1.30 + * @test
    1.31 + * @bug 8003639
    1.32 + * @summary convert lambda testng tests to jtreg and add them
    1.33 + * @run testng MethodReferenceTestNew
    1.34 + */
    1.35 +
    1.36 +import org.testng.annotations.Test;
    1.37 +
    1.38 +import static org.testng.Assert.assertEquals;
    1.39 +
    1.40 +/**
    1.41 + * @author Robert Field
    1.42 + */
    1.43 +
    1.44 +@Test
    1.45 +public class MethodReferenceTestNew {
    1.46 +
    1.47 +    interface M0<T> {
    1.48 +
    1.49 +        T m();
    1.50 +    }
    1.51 +
    1.52 +    static class N0 {
    1.53 +
    1.54 +        N0() {
    1.55 +        }
    1.56 +    }
    1.57 +
    1.58 +    interface M1<T> {
    1.59 +
    1.60 +        T m(Integer a);
    1.61 +    }
    1.62 +
    1.63 +    static class N1 {
    1.64 +
    1.65 +        int i;
    1.66 +
    1.67 +        N1(int i) {
    1.68 +            this.i = i;
    1.69 +        }
    1.70 +    }
    1.71 +
    1.72 +    interface M2<T> {
    1.73 +
    1.74 +        T m(Integer n, String o);
    1.75 +    }
    1.76 +
    1.77 +    static class N2 {
    1.78 +
    1.79 +        Number n;
    1.80 +        Object o;
    1.81 +
    1.82 +        N2(Number n, Object o) {
    1.83 +            this.n = n;
    1.84 +            this.o = o;
    1.85 +        }
    1.86 +
    1.87 +        public String toString() {
    1.88 +            return "N2(" + n + "," + o + ")";
    1.89 +        }
    1.90 +    }
    1.91 +
    1.92 +    interface MV {
    1.93 +
    1.94 +        NV m(Integer ai, int i);
    1.95 +    }
    1.96 +
    1.97 +    static class NV {
    1.98 +
    1.99 +        int i;
   1.100 +
   1.101 +        NV(int... v) {
   1.102 +            i = 0;
   1.103 +            for (int x : v) {
   1.104 +                i += x;
   1.105 +            }
   1.106 +        }
   1.107 +
   1.108 +        public String toString() {
   1.109 +            return "NV(" + i + ")";
   1.110 +        }
   1.111 +    }
   1.112 +
   1.113 +    public void testConstructorReference0() {
   1.114 +        M0<N0> q;
   1.115 +
   1.116 +        q = N0::new;
   1.117 +        assertEquals(q.m().getClass().getSimpleName(), "N0");
   1.118 +    }
   1.119 +
   1.120 +    public void testConstructorReference1() {
   1.121 +        M1<N1> q;
   1.122 +
   1.123 +        q = N1::new;
   1.124 +        assertEquals(q.m(14).getClass().getSimpleName(), "N1");
   1.125 +    }
   1.126 +
   1.127 +    public void testConstructorReference2() {
   1.128 +        M2<N2> q;
   1.129 +
   1.130 +        q = N2::new;
   1.131 +        assertEquals(q.m(7, "hi").toString(), "N2(7,hi)");
   1.132 +    }
   1.133 +
   1.134 +    public void testConstructorReferenceVarArgs() {
   1.135 +        MV q;
   1.136 +
   1.137 +        q = NV::new;
   1.138 +        assertEquals(q.m(5, 45).toString(), "NV(50)");
   1.139 +    }
   1.140 +
   1.141 +}

mercurial