AnnotationWithLambda.java revision 14716:3f4cce596ada
150276Speter/*
250276Speter * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3174993Srafan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
450276Speter *
550276Speter * This code is free software; you can redistribute it and/or modify it
650276Speter * under the terms of the GNU General Public License version 2 only, as
750276Speter * published by the Free Software Foundation.  Oracle designates this
850276Speter * particular file as subject to the "Classpath" exception as provided
950276Speter * by Oracle in the LICENSE file that accompanied this code.
1050276Speter *
1150276Speter * This code is distributed in the hope that it will be useful, but WITHOUT
1250276Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1350276Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1450276Speter * version 2 for more details (a copy is included in the LICENSE file that
1550276Speter * accompanied this code).
1650276Speter *
1750276Speter * You should have received a copy of the GNU General Public License version
1850276Speter * 2 along with this work; if not, write to the Free Software Foundation,
1950276Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2050276Speter *
2150276Speter * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2250276Speter * or visit www.oracle.com if you need additional information or have any
2350276Speter * questions.
2450276Speter */
2550276Speter
2650276Speter/*
2750276Speter * @test
2850276Speter * @bug 8147585
2950276Speter * @summary Check Annotation with Lambda, with or without parameter
30174993Srafan * @run testng AnnotationWithLambda
3150276Speter */
3250276Speter
3350276Speterimport java.lang.annotation.ElementType;
3450276Speterimport java.lang.annotation.Retention;
3550276Speterimport java.lang.annotation.RetentionPolicy;
3650276Speterimport java.lang.annotation.Target;
37174993Srafanimport java.lang.reflect.Method;
3850276Speterimport java.util.function.Consumer;
39174993Srafan
4050276Speterimport org.testng.annotations.*;
41174993Srafanimport static org.testng.Assert.*;
4250276Speter
43174993Srafanpublic class AnnotationWithLambda {
4450276Speter
45174993Srafan    @Test
4650276Speter    void testAnnotationWithLambda() {
47174993Srafan        Method[] methods = AnnotationWithLambda.MethodsWithAnnotations.class.getDeclaredMethods();
4850276Speter        for (Method method : methods) {
49174993Srafan            assertTrue((method.isAnnotationPresent(LambdaWithParameter.class)) &&
5050276Speter                       (method.isAnnotationPresent(LambdaWithoutParameter.class)));
51174993Srafan
5250276Speter        }
5350276Speter    }
5450276Speter
5550276Speter    static class MethodsWithAnnotations {
56166124Srafan
5750276Speter        @LambdaWithParameter
5850276Speter        @LambdaWithoutParameter
5950276Speter        public void testAnnotationLambda() {
6050276Speter        }
61166124Srafan    }
6250276Speter}
6350276Speter
6450276Speter@Target(value = ElementType.METHOD)
6550276Speter@Retention(RetentionPolicy.RUNTIME)
66166124Srafan@interface LambdaWithParameter {
6750276Speter    Consumer<Integer> f1 = a -> {
6850276Speter        System.out.println("lambda has parameter");
6950276Speter    };
7050276Speter}
71166124Srafan
7250276Speter@Target(value = ElementType.METHOD)
7350276Speter@Retention(RetentionPolicy.RUNTIME)
7450276Speter@interface LambdaWithoutParameter {
7550276Speter    Runnable r = () -> System.out.println("lambda without parameter");
7650276Speter}
7750276Speter
7850276Speter