6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.stage;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertTrue;
31
32 import org.junit.Test;
33
34 /**
35 * Test those attributes on Stage that should be immutable after Stage is visible.
36 *
37 */
38 public class StageMutabilityTest {
39
40 // ========== Tests for style
41
42 /**
43 * Tests the default value of style for a Stage
44 */
45 @Test public void testStyleDefault() {
46 Stage stage = new Stage();
47 assertEquals(StageStyle.DECORATED, stage.getStyle());
51 * Tests setting the value of style for a Stage
52 */
53 @Test public void testStyleSet() {
54 Stage stage = new Stage();
55 assertEquals(StageStyle.DECORATED, stage.getStyle());
56 stage.initStyle(StageStyle.UNDECORATED);
57 assertEquals(StageStyle.UNDECORATED, stage.getStyle());
58 stage.initStyle(StageStyle.DECORATED);
59 assertEquals(StageStyle.DECORATED, stage.getStyle());
60 stage.initStyle(StageStyle.TRANSPARENT);
61 assertEquals(StageStyle.TRANSPARENT, stage.getStyle());
62 stage.initStyle(StageStyle.UTILITY);
63 assertEquals(StageStyle.UTILITY, stage.getStyle());
64 }
65
66 /**
67 * Tests setting the value of style for a primary Stage
68 */
69 @Test public void testStyleSetPrimary() {
70 Stage stage = new Stage();
71 assertFalse(stage.isPrimary());
72 stage.impl_setPrimary(true);
73 assertTrue(stage.isPrimary());
74 assertEquals(StageStyle.DECORATED, stage.getStyle());
75 stage.initStyle(StageStyle.UNDECORATED);
76 assertEquals(StageStyle.UNDECORATED, stage.getStyle());
77 stage.initStyle(StageStyle.DECORATED);
78 assertEquals(StageStyle.DECORATED, stage.getStyle());
79 stage.initStyle(StageStyle.TRANSPARENT);
80 assertEquals(StageStyle.TRANSPARENT, stage.getStyle());
81 stage.initStyle(StageStyle.UTILITY);
82 assertEquals(StageStyle.UTILITY, stage.getStyle());
83 }
84
85 /**
86 * Tests initializing the value of style for a Stage in the constructor
87 */
88 @Test public void testStyleConstructor() {
89 Stage stage = new Stage(StageStyle.UNDECORATED);
90 assertEquals(StageStyle.UNDECORATED, stage.getStyle());
91 stage.initStyle(StageStyle.DECORATED);
92 assertEquals(StageStyle.DECORATED, stage.getStyle());
93 }
140
141 /**
142 * Tests setting the value of modality for a Stage
143 */
144 @Test public void testModalitySet() {
145 Stage stage = new Stage();
146 assertEquals(Modality.NONE, stage.getModality());
147 stage.initModality(Modality.WINDOW_MODAL);
148 assertEquals(Modality.WINDOW_MODAL, stage.getModality());
149 stage.initModality(Modality.APPLICATION_MODAL);
150 assertEquals(Modality.APPLICATION_MODAL, stage.getModality());
151 stage.initModality(Modality.NONE);
152 assertEquals(Modality.NONE, stage.getModality());
153 }
154
155 /**
156 * Tests setting the value of modality for a primary Stage
157 */
158 @Test public void testModalitySetPrimary() {
159 Stage stage = new Stage();
160 assertFalse(stage.isPrimary());
161 stage.impl_setPrimary(true);
162 assertTrue(stage.isPrimary());
163 assertEquals(Modality.NONE, stage.getModality());
164 try {
165 stage.initModality(Modality.WINDOW_MODAL);
166 // Error if we get here we didn't get the expected exception
167 assertTrue(false);
168 } catch (IllegalStateException ex) {
169 }
170 assertEquals(Modality.NONE, stage.getModality());
171 }
172
173 // TODO: Add more Modality test below:
174 // /**
175 // * Tests that setting the value of style on a visible Stage throws an exception
176 // */
177 // @Test public void testStyleSetWhileVisible() {
178 // Stage stage = new Stage();
179 // assertEquals(StageStyle.DECORATED, stage.getStyle());
180 // stage.show();
181 // try {
182 // stage.initStyle(StageStyle.UNDECORATED);
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.stage;
27
28 import javafx.stage.Modality;
29 import javafx.stage.Stage;
30 import javafx.stage.StageShim;
31 import javafx.stage.StageStyle;
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertFalse;
34 import static org.junit.Assert.assertTrue;
35
36 import org.junit.Test;
37
38 /**
39 * Test those attributes on Stage that should be immutable after Stage is visible.
40 *
41 */
42 public class StageMutabilityTest {
43
44 // ========== Tests for style
45
46 /**
47 * Tests the default value of style for a Stage
48 */
49 @Test public void testStyleDefault() {
50 Stage stage = new Stage();
51 assertEquals(StageStyle.DECORATED, stage.getStyle());
55 * Tests setting the value of style for a Stage
56 */
57 @Test public void testStyleSet() {
58 Stage stage = new Stage();
59 assertEquals(StageStyle.DECORATED, stage.getStyle());
60 stage.initStyle(StageStyle.UNDECORATED);
61 assertEquals(StageStyle.UNDECORATED, stage.getStyle());
62 stage.initStyle(StageStyle.DECORATED);
63 assertEquals(StageStyle.DECORATED, stage.getStyle());
64 stage.initStyle(StageStyle.TRANSPARENT);
65 assertEquals(StageStyle.TRANSPARENT, stage.getStyle());
66 stage.initStyle(StageStyle.UTILITY);
67 assertEquals(StageStyle.UTILITY, stage.getStyle());
68 }
69
70 /**
71 * Tests setting the value of style for a primary Stage
72 */
73 @Test public void testStyleSetPrimary() {
74 Stage stage = new Stage();
75 assertFalse(StageShim.isPrimary(stage));
76 stage.impl_setPrimary(true);
77 assertTrue(StageShim.isPrimary(stage));
78 assertEquals(StageStyle.DECORATED, stage.getStyle());
79 stage.initStyle(StageStyle.UNDECORATED);
80 assertEquals(StageStyle.UNDECORATED, stage.getStyle());
81 stage.initStyle(StageStyle.DECORATED);
82 assertEquals(StageStyle.DECORATED, stage.getStyle());
83 stage.initStyle(StageStyle.TRANSPARENT);
84 assertEquals(StageStyle.TRANSPARENT, stage.getStyle());
85 stage.initStyle(StageStyle.UTILITY);
86 assertEquals(StageStyle.UTILITY, stage.getStyle());
87 }
88
89 /**
90 * Tests initializing the value of style for a Stage in the constructor
91 */
92 @Test public void testStyleConstructor() {
93 Stage stage = new Stage(StageStyle.UNDECORATED);
94 assertEquals(StageStyle.UNDECORATED, stage.getStyle());
95 stage.initStyle(StageStyle.DECORATED);
96 assertEquals(StageStyle.DECORATED, stage.getStyle());
97 }
144
145 /**
146 * Tests setting the value of modality for a Stage
147 */
148 @Test public void testModalitySet() {
149 Stage stage = new Stage();
150 assertEquals(Modality.NONE, stage.getModality());
151 stage.initModality(Modality.WINDOW_MODAL);
152 assertEquals(Modality.WINDOW_MODAL, stage.getModality());
153 stage.initModality(Modality.APPLICATION_MODAL);
154 assertEquals(Modality.APPLICATION_MODAL, stage.getModality());
155 stage.initModality(Modality.NONE);
156 assertEquals(Modality.NONE, stage.getModality());
157 }
158
159 /**
160 * Tests setting the value of modality for a primary Stage
161 */
162 @Test public void testModalitySetPrimary() {
163 Stage stage = new Stage();
164 assertFalse(StageShim.isPrimary(stage));
165 stage.impl_setPrimary(true);
166 assertTrue(StageShim.isPrimary(stage));
167 assertEquals(Modality.NONE, stage.getModality());
168 try {
169 stage.initModality(Modality.WINDOW_MODAL);
170 // Error if we get here we didn't get the expected exception
171 assertTrue(false);
172 } catch (IllegalStateException ex) {
173 }
174 assertEquals(Modality.NONE, stage.getModality());
175 }
176
177 // TODO: Add more Modality test below:
178 // /**
179 // * Tests that setting the value of style on a visible Stage throws an exception
180 // */
181 // @Test public void testStyleSetWhileVisible() {
182 // Stage stage = new Stage();
183 // assertEquals(StageStyle.DECORATED, stage.getStyle());
184 // stage.show();
185 // try {
186 // stage.initStyle(StageStyle.UNDECORATED);
|