44545
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
|
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 |
/**
|
|
25 |
* @test
|
|
26 |
* @library src
|
|
27 |
* @build m/* Basic
|
|
28 |
* @run testng/othervm Basic
|
|
29 |
* @summary Basic test for annotations on modules
|
|
30 |
*/
|
|
31 |
|
|
32 |
import java.util.Arrays;
|
|
33 |
|
|
34 |
import p.annotation.Foo;
|
|
35 |
import p.annotation.Bar;
|
|
36 |
import p.annotation.Baz;
|
|
37 |
|
|
38 |
import org.testng.annotations.Test;
|
|
39 |
import static org.testng.Assert.*;
|
|
40 |
|
|
41 |
public class Basic {
|
|
42 |
|
|
43 |
final Module module = Foo.class.getModule();
|
|
44 |
|
|
45 |
/**
|
|
46 |
* {@code @Foo} does not have RUNTIME retention policy.
|
|
47 |
*/
|
|
48 |
@Test
|
|
49 |
public void testInvisibleAnnotation() {
|
|
50 |
assertFalse(module.isAnnotationPresent(Foo.class));
|
|
51 |
assertNull(module.getAnnotation(Foo.class));
|
|
52 |
}
|
|
53 |
|
|
54 |
/**
|
|
55 |
* {@code @Bar} has RUNTIME retention policy and value "bar"
|
|
56 |
*/
|
|
57 |
@Test
|
|
58 |
public void testBarAnnotation() {
|
|
59 |
assertTrue(module.isAnnotationPresent(Bar.class));
|
|
60 |
Bar bar = module.getAnnotation(Bar.class);
|
|
61 |
assertNotNull(bar);
|
|
62 |
assertEquals(bar.value(), "bar");
|
|
63 |
}
|
|
64 |
|
|
65 |
/**
|
|
66 |
* {@code @Baz} has RUNTIME retention policy has a repeating value
|
|
67 |
*/
|
|
68 |
@Test
|
|
69 |
public void testBazAnnotation() {
|
|
70 |
assertTrue(module.isAnnotationPresent(Baz.class));
|
|
71 |
Baz baz = module.getAnnotation(Baz.class);
|
|
72 |
assertNotNull(baz);
|
|
73 |
String[] expected = { "one", "two", "three" };
|
|
74 |
assertTrue(Arrays.equals(baz.value(), expected));
|
|
75 |
}
|
|
76 |
}
|