01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Anton Avtamonov
19: * @version $Revision$
20: */package javax.swing;
21:
22: import java.awt.Window;
23:
24: public class PopupFactoryTest extends BasicSwingTestCase {
25: public PopupFactoryTest(final String name) {
26: super (name);
27: }
28:
29: public void testGetSetSharedInstance() throws Exception {
30: assertNotNull(PopupFactory.getSharedInstance());
31: PopupFactory factory = new PopupFactory();
32: PopupFactory.setSharedInstance(factory);
33: assertSame(factory, PopupFactory.getSharedInstance());
34: testExceptionalCase(new IllegalArgumentCase() {
35: @Override
36: public void exceptionalAction() throws Exception {
37: PopupFactory.setSharedInstance(null);
38: }
39: });
40: }
41:
42: public void testGetPopup() throws Exception {
43: JButton content1 = new JButton();
44: Popup p1 = PopupFactory.getSharedInstance().getPopup(null,
45: content1, 10, 10);
46: p1.show();
47: Window w1 = SwingUtilities.getWindowAncestor(content1);
48: assertNotNull(w1);
49: assertTrue(w1.isVisible());
50: p1.hide();
51: assertFalse(w1.isVisible());
52: Popup p11 = PopupFactory.getSharedInstance().getPopup(null,
53: content1, 10, 10);
54: if (isHarmony()) {
55: assertSame(p1, p11);
56: }
57: JFrame frame = new JFrame();
58: JButton content2 = new JButton();
59: frame.getContentPane().add(content1);
60: frame.setVisible(true);
61: Popup p2 = PopupFactory.getSharedInstance().getPopup(frame,
62: content2, 10, 10);
63: p2.show();
64: Window w2 = SwingUtilities.getWindowAncestor(content2);
65: assertTrue(w2.isVisible());
66: frame.setVisible(false);
67: assertFalse(w2.isVisible());
68: if (isHarmony()) {
69: frame.dispose();
70: Popup p21 = PopupFactory.getSharedInstance().getPopup(
71: frame, content2, 10, 10);
72: assertSame(p2, p21);
73: }
74: }
75: }
|