Changeset 10375 in josm for trunk/test
- Timestamp:
- 2016-06-14T19:46:27+02:00 (8 years ago)
- 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 3 3 4 4 import static org.junit.Assert.assertEquals; 5 6 import java.awt.Rectangle;7 5 8 6 import org.junit.Before; … … 14 12 import org.openstreetmap.josm.data.coor.LatLon; 15 13 import org.openstreetmap.josm.gui.MapViewState.MapViewPoint; 16 import org.openstreetmap.josm.gui.util.GuiHelper;17 14 18 15 /** … … 22 19 public class MapViewStateTest { 23 20 21 private static final int WIDTH = 300; 24 22 private static final int HEIGHT = 200; 25 private static final int WIDTH = 300;26 private NavigatableComponent component;27 23 private MapViewState state; 28 24 … … 36 32 37 33 /** 38 * Create a new, fresh {@link NavigatableComponent}34 * Create the default state. 39 35 */ 40 36 @Before 41 37 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); 51 39 } 52 40 … … 59 47 assertHasViewCoords(WIDTH / 2, HEIGHT / 2, center); 60 48 61 component.zoomTo(new LatLon(3, 4));49 MapViewState newState = state.movedTo(center, new EastNorth(3, 4)); 62 50 63 51 // state should not change, but new state should. … … 65 53 assertHasViewCoords(WIDTH / 2, HEIGHT / 2, center); 66 54 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); 70 58 } 71 59 … … 109 97 @Test 110 98 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 113 102 114 103 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); 116 106 assertEquals("east", shouldEastNorth.east(), eastnorth.east(), 0.01); 117 107 assertEquals("north", shouldEastNorth.north(), eastnorth.north(), 0.01); 118 108 MapViewPoint reversed = state.getPointFor(shouldEastNorth); 119 assertHasViewCoords( 50, 70, reversed);109 assertHasViewCoords(WIDTH / 2, HEIGHT / 2, reversed); 120 110 121 111 LatLon latlon = p.getLatLon(); 122 LatLon shouldLatLon = Main.getProjection().eastNorth2latlon(shouldEastNorth);123 112 assertEquals("lat", shouldLatLon.lat(), latlon.lat(), 0.01); 124 113 assertEquals("lon", shouldLatLon.lon(), latlon.lon(), 0.01); -
trunk/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java
r9958 r10375 5 5 import static org.junit.Assert.assertThat; 6 6 7 import java.awt.Point; 7 8 import java.awt.Rectangle; 8 9 import java.awt.geom.Point2D; 10 11 import javax.swing.JFrame; 9 12 10 13 import org.CustomMatchers; … … 44 47 @Before 45 48 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 }; 47 55 component.setBounds(new Rectangle(WIDTH, HEIGHT)); 48 56 // wait for the event to be propagated. … … 52 60 } 53 61 }); 62 component.setVisible(true); 63 JFrame window = new JFrame(); 64 window.add(component); 65 component.updateLocationState(); 54 66 } 55 67
Note:
See TracChangeset
for help on using the changeset viewer.