Changeset 11931 in josm for trunk


Ignore:
Timestamp:
2017-04-16T20:45:20+02:00 (7 years ago)
Author:
Don-vip
Message:

improve unit test coverage

Location:
trunk
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r11889 r11931  
    170170    }
    171171
    172     private enum Polarity {
     172    enum Polarity {
    173173        NORTH(LatLon.NORTH_POLE),
    174174        SOUTH(LatLon.SOUTH_POLE);
     
    180180        }
    181181
    182         private LatLon getLatLon() {
     182        LatLon getLatLon() {
    183183            return latlon;
    184184        }
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r11848 r11931  
    142142    @Override
    143143    public LayerPainter attachToMapView(MapViewEvent event) {
    144         event.getMapView().addMouseListener(new MouseAdapter() {
    145             @Override
    146             public void mousePressed(MouseEvent e) {
    147                 if (e.getButton() != MouseEvent.BUTTON1)
    148                     return;
    149                 boolean mousePressedInButton = false;
    150                 for (Marker mkr : data) {
    151                     if (mkr.containsPoint(e.getPoint())) {
    152                         mousePressedInButton = true;
    153                         break;
    154                     }
    155                 }
    156                 if (!mousePressedInButton)
    157                     return;
    158                 mousePressed = true;
    159                 if (isVisible()) {
    160                     invalidate();
    161                 }
    162             }
    163 
    164             @Override
    165             public void mouseReleased(MouseEvent ev) {
    166                 if (ev.getButton() != MouseEvent.BUTTON1 || !mousePressed)
    167                     return;
    168                 mousePressed = false;
    169                 if (!isVisible())
    170                     return;
    171                 for (Marker mkr : data) {
    172                     if (mkr.containsPoint(ev.getPoint())) {
    173                         mkr.actionPerformed(new ActionEvent(this, 0, null));
    174                     }
    175                 }
    176                 invalidate();
    177             }
    178         });
     144        event.getMapView().addMouseListener(new MarkerMouseAdapter());
    179145
    180146        if (event.getMapView().playHeadMarker == null) {
     
    475441    }
    476442
     443    private final class MarkerMouseAdapter extends MouseAdapter {
     444        @Override
     445        public void mousePressed(MouseEvent e) {
     446            if (e.getButton() != MouseEvent.BUTTON1)
     447                return;
     448            boolean mousePressedInButton = false;
     449            for (Marker mkr : data) {
     450                if (mkr.containsPoint(e.getPoint())) {
     451                    mousePressedInButton = true;
     452                    break;
     453                }
     454            }
     455            if (!mousePressedInButton)
     456                return;
     457            mousePressed = true;
     458            if (isVisible()) {
     459                invalidate();
     460            }
     461        }
     462
     463        @Override
     464        public void mouseReleased(MouseEvent ev) {
     465            if (ev.getButton() != MouseEvent.BUTTON1 || !mousePressed)
     466                return;
     467            mousePressed = false;
     468            if (!isVisible())
     469                return;
     470            for (Marker mkr : data) {
     471                if (mkr.containsPoint(ev.getPoint())) {
     472                    mkr.actionPerformed(new ActionEvent(this, 0, null));
     473                }
     474            }
     475            invalidate();
     476        }
     477    }
     478
    477479    public static final class ShowHideMarkerText extends AbstractAction implements LayerAction {
    478480        private final transient MarkerLayer layer;
  • trunk/test/unit/org/openstreetmap/josm/data/projection/CustomProjectionTest.java

    r10870 r11931  
    1010import org.junit.Rule;
    1111import org.junit.Test;
     12import org.openstreetmap.josm.data.coor.LatLon;
     13import org.openstreetmap.josm.data.projection.CustomProjection.Polarity;
    1214import org.openstreetmap.josm.testutils.JOSMTestRules;
    1315
     
    7173                });
    7274    }
     75
     76    /**
     77     * Test {@link CustomProjection.Polarity}.
     78     */
     79    @Test
     80    public void testPolarity() {
     81        assertEquals(LatLon.NORTH_POLE, Polarity.NORTH.getLatLon());
     82        assertEquals(LatLon.SOUTH_POLE, Polarity.SOUTH.getLatLon());
     83    }
    7384}
Note: See TracChangeset for help on using the changeset viewer.