- Timestamp:
- 2007-07-04T00:34:16+02:00 (18 years ago)
- Location:
- test/org/openstreetmap/josm
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
test/org/openstreetmap/josm/testframework/MainMock.java
r269 r271 1 1 package org.openstreetmap.josm.testframework; 2 2 3 import java.awt.AWTEvent; 4 import java.awt.AWTException; 5 import java.awt.Toolkit; 6 import java.awt.event.AWTEventListener; 3 7 import java.io.IOException; 4 8 import java.util.Collection; 5 9 import java.util.Collections; 6 10 11 import javax.swing.JButton; 12 import javax.swing.JDialog; 7 13 import javax.swing.JFrame; 14 import javax.swing.JOptionPane; 15 import javax.swing.SwingUtilities; 8 16 17 import org.junit.Before; 9 18 import org.junit.BeforeClass; 10 19 import org.openstreetmap.josm.Main; … … 15 24 public class MainMock { 16 25 26 private static JDialog lastPopup; 27 28 @Before public void clearFoundPopup() { 29 lastPopup = null; 30 } 31 17 32 @BeforeClass public static void mockMain() throws Exception { 18 33 Main.pref = new Preferences(){ … … 27 42 Main.main = new Main(){}; 28 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 } 29 72 } -
test/org/openstreetmap/josm/testframework/MotherObject.java
r158 r271 16 16 import org.openstreetmap.josm.data.projection.Epsg4326; 17 17 18 public class MotherObject extends TestCase { 18 abstract public class MotherObject extends TestCase { 19 19 20 public static DataSet dataSet; 21 20 22 @Override protected void setUp() throws Exception { 21 23 super.setUp(); … … 23 25 } 24 26 25 public Node createNode(int id) { 27 public static Node createNode(int id) { 26 28 return createNode(id, 0, 0); 27 29 } 28 30 29 public Node createNode(int id, double lat, double lon) { 31 public static Node createNode(int id, double lat, double lon) { 30 32 Node n = createNode(lat, lon); 31 33 n.id = id; … … 33 35 } 34 36 35 public Node createNode() { 37 public static Node createNode() { 36 38 return createNode(Math.random()*360-180, Math.random()*180-90); 37 39 } 38 40 39 public Node createNode(double lat, double lon) { 40 return new Node(new LatLon(lat,lon)); 41 public static Node createNode(double lat, double lon) { 42 Node node = new Node(new LatLon(lat,lon)); 43 if (dataSet != null) 44 dataSet.nodes.add(node); 45 return node; 41 46 } 42 47 43 48 44 public Segment createSegment(long id) { 49 public static Segment createSegment(long id) { 45 50 Segment s = createSegment(); 46 51 s.id = id; 47 52 return s; 48 53 } 49 public Segment createSegment(long id, Node from, Node to) { 54 public static Segment createSegment(long id, Node from, Node to) { 50 55 Segment s = new Segment(from, to); 51 56 s.id = id; 52 57 return s; 53 58 } 54 public Segment createSegment() { 55 return new Segment(createNode(), createNode()); 59 public static Segment createSegment() { 60 Segment segment = new Segment(createNode(), createNode()); 61 if (dataSet != null) 62 dataSet.segments.add(segment); 63 return segment; 56 64 } 57 65 58 66 59 public Way createWay() { 67 public static Way createWay() { 60 68 return createWay(0); 61 69 } 62 public Way createWay(Segment... segments) { 70 public static Way createWay(Segment... segments) { 63 71 return createWay(0, segments); 64 72 } 65 public Way createWay(long id, Segment... segments) { 73 public static Way createWay(long id, Segment... segments) { 66 74 Way way = new Way(); 67 75 way.segments.addAll(Arrays.asList(segments)); 68 76 way.id = id; 77 if (dataSet != null) 78 dataSet.ways.add(way); 69 79 return way; 70 80 } 71 81 72 public DataSet createDataSet() { 82 public static DataSet createDataSet() { 73 83 DataSet ds = new DataSet(); 74 84 Node node1 = createNode(); … … 85 95 } 86 96 87 public void assertContainsSame(Collection<OsmPrimitive> data, OsmPrimitive... all) { 97 public static void assertContainsSame(Collection<OsmPrimitive> data, OsmPrimitive... all) { 88 98 Collection<OsmPrimitive> copy = new LinkedList<OsmPrimitive>(data); 89 99 copy.removeAll(Arrays.asList(all)); 90 100 assertEquals(0, copy.size()); 91 101 } 92 93 /**94 * To have JUnit shut up.95 */96 public void test() {97 }98 102 }
Note:
See TracChangeset
for help on using the changeset viewer.