source: josm/test/org/openstreetmap/josm/testframework/MainMock.java@ 271

Last change on this file since 271 was 271, checked in by imi, 17 years ago
  • fixed bug in 'combine way' that did not collect all properties.
File size: 2.1 KB
Line 
1package org.openstreetmap.josm.testframework;
2
3import java.awt.AWTEvent;
4import java.awt.AWTException;
5import java.awt.Toolkit;
6import java.awt.event.AWTEventListener;
7import java.io.IOException;
8import java.util.Collection;
9import java.util.Collections;
10
11import javax.swing.JButton;
12import javax.swing.JDialog;
13import javax.swing.JFrame;
14import javax.swing.JOptionPane;
15import javax.swing.SwingUtilities;
16
17import org.junit.Before;
18import org.junit.BeforeClass;
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.data.Preferences;
21import org.openstreetmap.josm.data.projection.Epsg4326;
22import org.openstreetmap.josm.gui.PleaseWaitDialog;
23
24public class MainMock {
25
26 private static JDialog lastPopup;
27
28 @Before public void clearFoundPopup() {
29 lastPopup = null;
30 }
31
32 @BeforeClass public static void mockMain() throws Exception {
33 Main.pref = new Preferences(){
34 @Override protected void save() {}
35 @Override public void load() throws IOException {}
36 @Override public Collection<Bookmark> loadBookmarks() throws IOException {return Collections.emptyList();}
37 @Override public void saveBookmarks(Collection<Bookmark> bookmarks) throws IOException {}
38 };
39 Main.parent = new JFrame();
40 Main.proj = new Epsg4326();
41 Main.pleaseWaitDlg = new PleaseWaitDialog(Main.parent);
42 Main.main = new Main(){};
43 }
44
45 @BeforeClass public static void startPopupKiller() throws AWTException {
46 Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener(){
47 public void eventDispatched(AWTEvent event) {
48 if (event.getSource() instanceof JButton) {
49 JButton b = (JButton)event.getSource();
50 if (b.getParent().getParent() instanceof JOptionPane) {
51 lastPopup = (JDialog)SwingUtilities.getRoot(b);
52 b.doClick();
53 }
54 }
55 }
56 }, AWTEvent.FOCUS_EVENT_MASK);
57 }
58
59 public void assertPopup() {
60 waitForPopup();
61 lastPopup = null;
62 }
63
64 public JDialog waitForPopup() {
65 for (int i = 0; i < 100; ++i) {
66 if (lastPopup != null)
67 return lastPopup;
68 try {Thread.sleep(10);} catch (InterruptedException e) {}
69 }
70 throw new AssertionError("Expected Popup dialog");
71 }
72}
Note: See TracBrowser for help on using the repository browser.