blob: 1b4ccb705116c06acda3e5d84ab2a42c44411b57 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4891872 4989735 4990789 5020490
27 * @summary Check isEnum() method
28 * @author Joseph D. Darcy
29 * @compile -source 1.5 IsEnum.java
30 * @run main IsEnum
31 */
32
33import java.lang.annotation.*;
34
35public class IsEnum {
36
37 static int test(Class clazz, boolean expected) {
38 int status = (clazz.isEnum() == expected)?0:1;
39
40 if (status == 1) {
41 System.err.println("Unexpected enum status for " + clazz);
42 }
43 return status;
44 }
45
46 public static void main(String argv[]) {
47 int failures = 0;
48
49 failures += test(IsEnum.class, false);
50 failures += test(String.class, false);
51 failures += test(Enum.class, false);
52 failures += test(java.math.RoundingMode.class, true);
53
54 // Classes in java.lang.annoation
55 failures += test(Annotation.class, false);
56 failures += test(ElementType.class, true);
57 failures += test(Retention.class, false);
58 failures += test(RetentionPolicy.class, true);
59 failures += test(Target.class, false);
60 failures += test(EnumPoseur.class, false);
61
62 // Classes for specialized enum constants aren't enum's
63 failures += test(SpecialEnum.class, true);
64 failures += test(SpecialEnum.RED.getClass(), false);
65 failures += test(SpecialEnum.GREEN.getClass(), true);
66
67 if (failures > 0) {
68 throw new RuntimeException("Unexepcted enum status detected.");
69 }
70 }
71}
72
73enum SpecialEnum {
74 RED {
75 String special() {return "riding hood";}
76 },
77
78 GREEN;
79
80 String special() {return "how was my valley";}
81}