jdk/test/java/lang/ModuleTests/annotation/Basic.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
child 45652 33342314ce89
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     1
/*
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     4
 *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     8
 *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    13
 * accompanied this code).
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    14
 *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    18
 *
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    21
 * questions.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    22
 */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    23
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    24
/**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    25
 * @test
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    26
 * @library src
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    27
 * @build m/* Basic
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    28
 * @run testng/othervm Basic
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    29
 * @summary Basic test for annotations on modules
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    30
 */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    31
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    32
import java.util.Arrays;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    33
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    34
import p.annotation.Foo;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    35
import p.annotation.Bar;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    36
import p.annotation.Baz;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    37
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    38
import org.testng.annotations.Test;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    39
import static org.testng.Assert.*;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    40
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    41
public class Basic {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    42
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    43
    final Module module = Foo.class.getModule();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    44
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    45
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    46
     * {@code @Foo} does not have RUNTIME retention policy.
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    47
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    48
    @Test
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    49
    public void testInvisibleAnnotation() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    50
        assertFalse(module.isAnnotationPresent(Foo.class));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    51
        assertNull(module.getAnnotation(Foo.class));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    52
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    53
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    54
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    55
     * {@code @Bar} has RUNTIME retention policy and value "bar"
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    56
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    57
    @Test
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    58
    public void testBarAnnotation() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    59
        assertTrue(module.isAnnotationPresent(Bar.class));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    60
        Bar bar = module.getAnnotation(Bar.class);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    61
        assertNotNull(bar);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    62
        assertEquals(bar.value(), "bar");
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    63
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    64
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    65
    /**
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    66
     * {@code @Baz} has RUNTIME retention policy has a repeating value
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    67
     */
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    68
    @Test
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    69
    public void testBazAnnotation() {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    70
        assertTrue(module.isAnnotationPresent(Baz.class));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    71
        Baz baz = module.getAnnotation(Baz.class);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    72
        assertNotNull(baz);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    73
        String[] expected = { "one", "two", "three" };
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    74
        assertTrue(Arrays.equals(baz.value(), expected));
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    75
    }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents:
diff changeset
    76
}