Changeset 10375 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2016-06-14T19:46:27+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #12959 - Move state changes to MapViewState class (patch by michael2402) - gscore-core + checkstyle fixes

Location:
trunk/test/unit/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/MapViewStateTest.java

    r10343 r10375  
    33
    44import static org.junit.Assert.assertEquals;
    5 
    6 import java.awt.Rectangle;
    75
    86import org.junit.Before;
     
    1412import org.openstreetmap.josm.data.coor.LatLon;
    1513import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
    16 import org.openstreetmap.josm.gui.util.GuiHelper;
    1714
    1815/**
     
    2219public class MapViewStateTest {
    2320
     21    private static final int WIDTH = 300;
    2422    private static final int HEIGHT = 200;
    25     private static final int WIDTH = 300;
    26     private NavigatableComponent component;
    2723    private MapViewState state;
    2824
     
    3632
    3733    /**
    38      * Create a new, fresh {@link NavigatableComponent}
     34     * Create the default state.
    3935     */
    4036    @Before
    4137    public void setUp() {
    42         component = new NavigatableComponent();
    43         component.setBounds(new Rectangle(WIDTH, HEIGHT));
    44         // wait for the event to be propagated.
    45         GuiHelper.runInEDTAndWait(new Runnable() {
    46             @Override
    47             public void run() {
    48             }
    49         });
    50         state = new MapViewState(component);
     38        state = MapViewState.createDefaultState(WIDTH, HEIGHT);
    5139    }
    5240
     
    5947        assertHasViewCoords(WIDTH / 2, HEIGHT / 2, center);
    6048
    61         component.zoomTo(new LatLon(3, 4));
     49        MapViewState newState = state.movedTo(center, new EastNorth(3, 4));
    6250
    6351        // state should not change, but new state should.
     
    6553        assertHasViewCoords(WIDTH / 2, HEIGHT / 2, center);
    6654
    67         center = new MapViewState(component).getCenter();
    68         assertEquals("x", 3, center.getLatLon().lat(), 0.01);
    69         assertEquals("y", 4, center.getLatLon().lon(), 0.01);
     55        center = newState.getCenter();
     56        assertEquals("east", 3, center.getEastNorth().east(), 0.01);
     57        assertEquals("north", 4, center.getEastNorth().north(), 0.01);
    7058    }
    7159
     
    10997    @Test
    11098    public void testPointConversions() {
    111         MapViewPoint p = state.getForView(50, 70);
    112         assertHasViewCoords(50, 70, p);
     99        MapViewPoint p = state.getForView(WIDTH / 2, HEIGHT / 2);
     100        assertHasViewCoords(WIDTH / 2, HEIGHT / 2, p);
     101
    113102
    114103        EastNorth eastnorth = p.getEastNorth();
    115         EastNorth shouldEastNorth = component.getEastNorth(50, 70);
     104        LatLon shouldLatLon = Main.getProjection().getWorldBoundsLatLon().getCenter();
     105        EastNorth shouldEastNorth = Main.getProjection().latlon2eastNorth(shouldLatLon);
    116106        assertEquals("east", shouldEastNorth.east(), eastnorth.east(), 0.01);
    117107        assertEquals("north", shouldEastNorth.north(), eastnorth.north(), 0.01);
    118108        MapViewPoint reversed = state.getPointFor(shouldEastNorth);
    119         assertHasViewCoords(50, 70, reversed);
     109        assertHasViewCoords(WIDTH / 2, HEIGHT / 2, reversed);
    120110
    121111        LatLon latlon = p.getLatLon();
    122         LatLon shouldLatLon = Main.getProjection().eastNorth2latlon(shouldEastNorth);
    123112        assertEquals("lat", shouldLatLon.lat(), latlon.lat(), 0.01);
    124113        assertEquals("lon", shouldLatLon.lon(), latlon.lon(), 0.01);
  • trunk/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java

    r9958 r10375  
    55import static org.junit.Assert.assertThat;
    66
     7import java.awt.Point;
    78import java.awt.Rectangle;
    89import java.awt.geom.Point2D;
     10
     11import javax.swing.JFrame;
    912
    1013import org.CustomMatchers;
     
    4447    @Before
    4548    public void setUp() {
    46         component = new NavigatableComponent();
     49        component = new NavigatableComponent() {
     50            @Override
     51            public Point getLocationOnScreen() {
     52                return new Point(30, 40);
     53            }
     54        };
    4755        component.setBounds(new Rectangle(WIDTH, HEIGHT));
    4856        // wait for the event to be propagated.
     
    5260            }
    5361        });
     62        component.setVisible(true);
     63        JFrame window = new JFrame();
     64        window.add(component);
     65        component.updateLocationState();
    5466    }
    5567
Note: See TracChangeset for help on using the changeset viewer.