Changeset 271 in josm for test/org/openstreetmap


Ignore:
Timestamp:
2007-07-04T00:34:16+02:00 (17 years ago)
Author:
imi
Message:
  • fixed bug in 'combine way' that did not collect all properties.
Location:
test/org/openstreetmap/josm
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • test/org/openstreetmap/josm/testframework/MainMock.java

    r269 r271  
    11package org.openstreetmap.josm.testframework;
    22
     3import java.awt.AWTEvent;
     4import java.awt.AWTException;
     5import java.awt.Toolkit;
     6import java.awt.event.AWTEventListener;
    37import java.io.IOException;
    48import java.util.Collection;
    59import java.util.Collections;
    610
     11import javax.swing.JButton;
     12import javax.swing.JDialog;
    713import javax.swing.JFrame;
     14import javax.swing.JOptionPane;
     15import javax.swing.SwingUtilities;
    816
     17import org.junit.Before;
    918import org.junit.BeforeClass;
    1019import org.openstreetmap.josm.Main;
     
    1524public class MainMock {
    1625
     26        private static JDialog lastPopup;
     27
     28        @Before public void clearFoundPopup() {
     29                lastPopup = null;
     30        }
     31       
    1732        @BeforeClass public static void mockMain() throws Exception {
    1833                Main.pref = new Preferences(){
     
    2742                Main.main = new Main(){};
    2843        }
     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    }
    2972}
  • test/org/openstreetmap/josm/testframework/MotherObject.java

    r158 r271  
    1616import org.openstreetmap.josm.data.projection.Epsg4326;
    1717
    18 public class MotherObject extends TestCase {
     18abstract public class MotherObject extends TestCase {
    1919
     20        public static DataSet dataSet;
     21       
    2022        @Override protected void setUp() throws Exception {
    2123            super.setUp();
     
    2325    }
    2426
    25         public Node createNode(int id) {
     27        public static Node createNode(int id) {
    2628                return createNode(id, 0, 0);
    2729        }
    2830       
    29         public Node createNode(int id, double lat, double lon) {
     31        public static Node createNode(int id, double lat, double lon) {
    3032                Node n = createNode(lat, lon);
    3133                n.id = id;
     
    3335        }
    3436
    35         public Node createNode() {
     37        public static Node createNode() {
    3638                return createNode(Math.random()*360-180, Math.random()*180-90);
    3739        }
    3840
    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;
    4146    }
    4247       
    4348       
    44         public Segment createSegment(long id) {
     49        public static Segment createSegment(long id) {
    4550                Segment s = createSegment();
    4651                s.id = id;
    4752                return s;
    4853        }
    49         public Segment createSegment(long id, Node from, Node to) {
     54        public static Segment createSegment(long id, Node from, Node to) {
    5055                Segment s = new Segment(from, to);
    5156                s.id = id;
    5257                return s;
    5358        }
    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;
    5664        }
    5765       
    5866       
    59         public Way createWay() {
     67        public static Way createWay() {
    6068                return createWay(0);
    6169        }
    62         public Way createWay(Segment... segments) {
     70        public static Way createWay(Segment... segments) {
    6371                return createWay(0, segments);
    6472        }
    65         public Way createWay(long id, Segment... segments) {
     73        public static Way createWay(long id, Segment... segments) {
    6674                Way way = new Way();
    6775                way.segments.addAll(Arrays.asList(segments));
    6876                way.id = id;
     77                if (dataSet != null)
     78                        dataSet.ways.add(way);
    6979                return way;
    7080        }
    7181       
    72         public DataSet createDataSet() {
     82        public static DataSet createDataSet() {
    7383            DataSet ds = new DataSet();
    7484                Node node1 = createNode();
     
    8595    }
    8696
    87         public void assertContainsSame(Collection<OsmPrimitive> data, OsmPrimitive... all) {
     97        public static void assertContainsSame(Collection<OsmPrimitive> data, OsmPrimitive... all) {
    8898                Collection<OsmPrimitive> copy = new LinkedList<OsmPrimitive>(data);
    8999                copy.removeAll(Arrays.asList(all));
    90100                assertEquals(0, copy.size());
    91101    }
    92        
    93         /**
    94          * To have JUnit shut up.
    95          */
    96         public void test() {
    97         }
    98102}
Note: See TracChangeset for help on using the changeset viewer.