Changeset 11867 in josm for trunk/test/unit
- Timestamp:
- 2017-04-09T16:00:43+02:00 (8 years ago)
- Location:
- trunk/test/unit/org
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/CustomMatchers.java
r10691 r11867 4 4 import java.awt.geom.Point2D; 5 5 import java.util.Collection; 6 import java.util.Objects; 6 7 import java.util.function.Predicate; 7 8 … … 88 89 */ 89 90 public static Matcher<? super Point2D> is(final Point2D expected) { 90 return new CustomTypeSafeMatcher<Point2D>( "the same Point2D") {91 return new CustomTypeSafeMatcher<Point2D>(Objects.toString(expected)) { 91 92 @Override 92 93 protected boolean matchesSafely(Point2D actual) { … … 102 103 */ 103 104 public static Matcher<? super LatLon> is(final LatLon expected) { 104 return new CustomTypeSafeMatcher<LatLon>( "the same LatLon") {105 return new CustomTypeSafeMatcher<LatLon>(Objects.toString(expected)) { 105 106 @Override 106 107 protected boolean matchesSafely(LatLon actual) { … … 117 118 */ 118 119 public static Matcher<? super EastNorth> is(final EastNorth expected) { 119 return new CustomTypeSafeMatcher<EastNorth>( "the same EastNorth") {120 return new CustomTypeSafeMatcher<EastNorth>(Objects.toString(expected)) { 120 121 @Override 121 122 protected boolean matchesSafely(EastNorth actual) { -
trunk/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java
r11838 r11867 8 8 import java.awt.Rectangle; 9 9 import java.awt.geom.Point2D; 10 import java.util.Objects; 10 11 11 12 import javax.swing.JPanel; 12 13 13 14 import org.CustomMatchers; 15 import org.hamcrest.CustomTypeSafeMatcher; 16 import org.hamcrest.Matcher; 14 17 import org.junit.Before; 15 18 import org.junit.Rule; … … 112 115 component.zoomTo(new LatLon(10, 10)); 113 116 Point2D shouldBeCenter = component.getPoint2D(new LatLon(10, 10)); 114 // center may move 0.5 pixels for alignment, see {@link NavigatableComponent#zoomTo(EastNorth, double, boolean)}117 // 0.5 pixel tolerance, see isAfterZoom 115 118 assertEquals(shouldBeCenter.getX(), WIDTH / 2., 0.5); 116 119 assertEquals(shouldBeCenter.getY(), HEIGHT / 2., 0.5); … … 128 131 component.zoomToFactor(0.5); 129 132 assertEquals(initialScale / 2, component.getScale(), 0.00000001); 130 assertThat(component.getCenter(), CustomMatchers.is(center));133 assertThat(component.getCenter(), isAfterZoom(center, component.getScale())); 131 134 component.zoomToFactor(2); 132 135 assertEquals(initialScale, component.getScale(), 0.00000001); 133 assertThat(component.getCenter(), CustomMatchers.is(center));136 assertThat(component.getCenter(), isAfterZoom(center, component.getScale())); 134 137 135 138 // zoomToFactor(EastNorth, double) … … 137 140 component.zoomToFactor(newCenter, 0.5); 138 141 assertEquals(initialScale / 2, component.getScale(), 0.00000001); 139 assert Equals(newCenter, component.getCenter());142 assertThat(component.getCenter(), isAfterZoom(newCenter, component.getScale())); 140 143 component.zoomToFactor(newCenter, 2); 141 144 assertEquals(initialScale, component.getScale(), 0.00000001); 142 assert Equals(newCenter, component.getCenter());145 assertThat(component.getCenter(), isAfterZoom(newCenter, component.getScale())); 143 146 } 144 147 … … 168 171 component.zoomToFactor(0, 0, 0.5); 169 172 assertEquals(initialScale / 2, component.getScale(), 0.00000001); 170 assertThat(component.getEastNorth(0, 0), CustomMatchers.is(testPoint1));173 assertThat(component.getEastNorth(0, 0), isAfterZoom(testPoint1, component.getScale())); 171 174 component.zoomToFactor(0, 0, 2); 172 175 assertEquals(initialScale, component.getScale(), 0.00000001); 173 assertThat(component.getEastNorth(0, 0), CustomMatchers.is(testPoint1));176 assertThat(component.getEastNorth(0, 0), isAfterZoom(testPoint1, component.getScale())); 174 177 175 178 component.zoomToFactor(200, 150, 0.5); 176 179 assertEquals(initialScale / 2, component.getScale(), 0.00000001); 177 assertThat(component.getEastNorth(200, 150), CustomMatchers.is(testPoint2));180 assertThat(component.getEastNorth(200, 150), isAfterZoom(testPoint2, component.getScale())); 178 181 component.zoomToFactor(200, 150, 2); 179 182 assertEquals(initialScale, component.getScale(), 0.00000001); 180 assertThat(component.getEastNorth(200, 150), CustomMatchers.is(testPoint2));183 assertThat(component.getEastNorth(200, 150), isAfterZoom(testPoint2, component.getScale())); 181 184 182 185 } … … 206 209 } 207 210 211 /** 212 * Check that EastNorth is the same as expected after zooming the NavigatableComponent. 213 * 214 * Adds tolerance of 0.5 pixel for pixel grid alignment, see 215 * {@link NavigatableComponent#zoomTo(EastNorth, double, boolean)} 216 * @param expected expected 217 * @param scale current scale 218 * @return Matcher object 219 */ 220 private Matcher<EastNorth> isAfterZoom(EastNorth expected, double scale) { 221 return new CustomTypeSafeMatcher<EastNorth>(Objects.toString(expected)) { 222 @Override 223 protected boolean matchesSafely(EastNorth actual) { 224 // compare pixels (east/north divided by scale) 225 return Math.abs((expected.getX() - actual.getX()) / scale) <= 0.5 226 && Math.abs((expected.getY() - actual.getY()) / scale) <= 0.5; 227 } 228 }; 229 } 230 208 231 }
Note:
See TracChangeset
for help on using the changeset viewer.