|
1 /* |
|
2 * Copyright (c) 2013, 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 package test; |
|
24 |
|
25 import java.util.Arrays; |
|
26 import java.util.HashSet; |
|
27 import java.util.Set; |
|
28 |
|
29 /* |
|
30 * @test |
|
31 * @bug 8025141 |
|
32 * @summary Interfaces must not contain non-public fields, ensure $assertionsDisabled |
|
33 * is not generated into an interface |
|
34 * @compile Assertions.java |
|
35 * @run main/othervm -da test.Assertions |
|
36 * @run main/othervm -ea:test.Assertions test.Assertions Inner |
|
37 * @run main/othervm -ea:test.Outer test.Assertions Outer |
|
38 * @run main/othervm -ea:test.Another test.Assertions Another.Inner |
|
39 * @run main/othervm -ea:test... test.Assertions Inner Outer Another.Inner |
|
40 */ |
|
41 |
|
42 public class Assertions { |
|
43 interface Inner { |
|
44 default void testInner() { |
|
45 assert false; |
|
46 } |
|
47 } |
|
48 |
|
49 static class InnerImpl implements Inner {} |
|
50 |
|
51 static class OuterImpl implements Outer {} |
|
52 |
|
53 static class AnotherInnerImpl implements Another.Inner {} |
|
54 |
|
55 public static void main(String... args) { |
|
56 Set<String> shouldThrowAssert = new HashSet<String>(Arrays.asList(args)); |
|
57 try { |
|
58 new InnerImpl().testInner(); |
|
59 if (shouldThrowAssert.contains("Inner")) { |
|
60 throw new IllegalStateException("AssertionError expected, but not thrown."); |
|
61 } |
|
62 } catch (AssertionError e) { |
|
63 if (!shouldThrowAssert.contains("Inner")) { |
|
64 throw new IllegalStateException("AssertionError not expected, but thrown."); |
|
65 } |
|
66 } |
|
67 try { |
|
68 new OuterImpl().testOuter(); |
|
69 if (shouldThrowAssert.contains("Outer")) { |
|
70 throw new IllegalStateException("AssertionError expected, but not thrown."); |
|
71 } |
|
72 } catch (AssertionError e) { |
|
73 if (!shouldThrowAssert.contains("Outer")) { |
|
74 throw new IllegalStateException("AssertionError not expected, but thrown."); |
|
75 } |
|
76 } |
|
77 try { |
|
78 new AnotherInnerImpl().testAnotherInner(); |
|
79 if (shouldThrowAssert.contains("Another.Inner")) { |
|
80 throw new IllegalStateException("AssertionError expected, but not thrown."); |
|
81 } |
|
82 } catch (AssertionError e) { |
|
83 if (!shouldThrowAssert.contains("Another.Inner")) { |
|
84 throw new IllegalStateException("AssertionError not expected, but thrown."); |
|
85 } |
|
86 } |
|
87 } |
|
88 } |
|
89 |
|
90 interface Outer { |
|
91 default void testOuter() { |
|
92 assert false; |
|
93 } |
|
94 } |
|
95 |
|
96 @interface Another { |
|
97 interface Inner { |
|
98 default void testAnotherInner() { |
|
99 assert false; |
|
100 } |
|
101 } |
|
102 } |