1111
1212import java .util .Map ;
1313import java .util .concurrent .Callable ;
14+ import java .util .function .Consumer ;
1415import java .util .function .IntFunction ;
1516import java .lang .AssertionError ;
1617
@@ -81,28 +82,28 @@ public static void probePixels(BufferedImage image, int top, int right, int bott
8182 image ,
8283 image .getWidth ()/2 ,
8384 stripAlpha (ImmutableMap .of (0xffffff , "w" , top , "t" )),
84- "w+ t.*" ,
85+ "w* t.*" ,
8586 true
8687 );
8788 ImagePatternMatching .columnMatch (
8889 image ,
8990 image .getWidth ()/2 ,
9091 stripAlpha (ImmutableMap .of (0xffffff , "w" , bottom , "b" )),
91- ".*bw+ " ,
92+ ".*bw* " ,
9293 true
9394 );
9495 ImagePatternMatching .rowMatch (
9596 image ,
9697 image .getHeight ()/2 ,
9798 stripAlpha (ImmutableMap .of (0xffffff , "w" , left , "l" )),
98- "w+ l.*" ,
99+ "w* l.*" ,
99100 true
100101 );
101102 ImagePatternMatching .rowMatch (
102103 image ,
103104 image .getHeight ()/2 ,
104105 stripAlpha (ImmutableMap .of (0xffffff , "w" , right , "r" )),
105- ".*rw+ " ,
106+ ".*rw* " ,
106107 true
107108 );
108109 }
@@ -125,8 +126,7 @@ public static void probePixels(BufferedImage image, int top, int right, int bott
125126
126127 protected static BufferedImage probeScratchImage ;
127128
128- public void probeSlippyMapPixels (int top , int right , int bottom , int left ) {
129-
129+ public void renderAndAssert (final Consumer <BufferedImage > assertion ) {
130130 if (probeScratchImage == null || probeScratchImage .getWidth () != this .slippyMap .getSize ().width || probeScratchImage .getHeight () != this .slippyMap .getSize ().height ) {
131131 probeScratchImage = new BufferedImage (
132132 this .slippyMap .getSize ().width ,
@@ -142,7 +142,7 @@ public void probeSlippyMapPixels(int top, int right, int bottom, int left) {
142142 this .slippyMap .paint (g );
143143
144144 try {
145- probePixels (probeScratchImage , top , right , bottom , left );
145+ assertion . accept (probeScratchImage );
146146 } catch (AssertionError e ) {
147147 e .printStackTrace ();
148148 System .err .println ("Writing problematic image to failed.png" );
@@ -230,34 +230,34 @@ public void testInitPrefRecordActiveDisabled() throws Exception {
230230 mainMap .mapView .zoomTo (new Bounds (actualBounds .getMinLat (), actualBounds .getMinLon ()+0.005 , actualBounds .getMaxLat (), actualBounds .getMaxLon ()+0.005 ));
231231
232232 this .assertControlStates (12 , false , true );
233- this .probeSlippyMapPixels ( 0x0 , 0x0 , 0x0 , 0xff80ff );
233+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x0 , 0x0 , 0xff80ff ) );
234234
235235 // another unrecorded pure pan
236236 actualBounds = mainMap .mapView .getState ().getViewArea ().getLatLonBoundsBox ();
237237 mainMap .mapView .zoomTo (new Bounds (actualBounds .getMinLat ()+0.001 , actualBounds .getMinLon (), actualBounds .getMaxLat ()+0.001 , actualBounds .getMaxLon ()));
238238
239239 this .assertControlStates (12 , false , true );
240- this .probeSlippyMapPixels ( 0x0 , 0x0 , 0x0 , 0xff80ff );
240+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x0 , 0x0 , 0xff80ff ) );
241241
242242 // now we activate recording briefly
243243 this .recordToggleButton .doClick ();
244244
245245 this .assertControlStates (12 , true , true );
246- this .probeSlippyMapPixels ( 0x0 , 0x0 , 0x0 , 0xff80ff );
246+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x0 , 0x0 , 0xff80ff ) );
247247
248248 // but we desctivate it without a viewport change
249249 this .recordToggleButton .doClick ();
250250
251251 this .assertControlStates (12 , false , true );
252- this .probeSlippyMapPixels ( 0x0 , 0x0 , 0x0 , 0xff80ff );
252+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x0 , 0x0 , 0xff80ff ) );
253253
254254 // another unrecorded pure pan back down
255255 actualBounds = mainMap .mapView .getState ().getViewArea ().getLatLonBoundsBox ();
256256 mainMap .mapView .zoomTo (new Bounds (actualBounds .getMinLat ()-0.001 , actualBounds .getMinLon (), actualBounds .getMaxLat ()-0.001 , actualBounds .getMaxLon ()));
257257
258258 // should have revealed another painted region
259259 this .assertControlStates (12 , false , true );
260- this .probeSlippyMapPixels ( 0xff80ff , 0x0 , 0x0 , 0xff80ff );
260+ this .renderAndAssert ( i -> probePixels ( i , 0xff80ff , 0x0 , 0x0 , 0xff80ff ) );
261261 }
262262
263263 @ Test
@@ -275,17 +275,17 @@ public void testInitPrefRecordActiveEnabled() throws Exception {
275275
276276 this .assertControlStates (10 , true , true );
277277 assertFalse (this .recordToggleButton .getToolTipText ().contains ("disabled" ));
278- this .probeSlippyMapPixels ( 0x0 , 0x0 , 0x0 , 0x0 );
278+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x0 , 0x0 , 0x0 ) );
279279
280280 mainMap .mapView .zoomTo (new Bounds (-0.0005 , -0.0005 , 0.001 , 0.001 ));
281281 this .assertControlStates (10 , true , true );
282282 // it should be ok that the "initial" position wasn't recorded - the initial mapview position is often not
283283 // reliable to use
284- this .probeSlippyMapPixels ( 0x0 , 0x0 , 0x0 , 0x0 );
284+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x0 , 0x0 , 0x0 ) );
285285
286286 mainMap .mapView .zoomTo (new Bounds (-0.0004 , -0.0004 , 0.001 , 0.001 ));
287287 this .assertControlStates (10 , true , true );
288- this .probeSlippyMapPixels ( 0x0 , 0x0 , 0x00ffff , 0x00ffff );
288+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x0 , 0x00ffff , 0x00ffff ) );
289289
290290 this .dialog .hideDialog ();
291291
@@ -294,14 +294,14 @@ public void testInitPrefRecordActiveEnabled() throws Exception {
294294
295295 this .dialog .showDialog ();
296296 // slippy map should take heed of the movement while the dialog was closed
297- this .probeSlippyMapPixels ( 0x0 , 0x00ffff , 0x0 , 0x0 );
297+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x00ffff , 0x0 , 0x0 ) );
298298
299299 this .clearButton .doClick ();
300300
301301 Thread .sleep (50 );
302302
303303 this .assertControlStates (10 , true , true );
304- this .probeSlippyMapPixels ( 0x0 , 0x0 , 0x0 , 0x0 );
304+ this .renderAndAssert ( i -> probePixels ( i , 0x0 , 0x0 , 0x0 , 0x0 ) );
305305 }
306306
307307 @ Test
0 commit comments