11// License: GPL. For details, see LICENSE file.
22package org .openstreetmap .josm .actions .upload ;
33
4+ import static org .junit .jupiter .api .Assertions .assertEquals ;
45import static org .junit .jupiter .api .Assertions .assertTrue ;
56
6- import org .junit .jupiter .api .extension .RegisterExtension ;
7+ import java .util .Collections ;
8+
9+ import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
10+ import mockit .Mock ;
711import org .junit .jupiter .api .Test ;
12+ import org .junit .jupiter .api .extension .RegisterExtension ;
13+ import org .junit .jupiter .params .ParameterizedTest ;
14+ import org .junit .jupiter .params .provider .ValueSource ;
15+ import org .openstreetmap .josm .TestUtils ;
816import org .openstreetmap .josm .data .APIDataSet ;
17+ import org .openstreetmap .josm .data .Bounds ;
18+ import org .openstreetmap .josm .data .DataSource ;
19+ import org .openstreetmap .josm .data .coor .LatLon ;
20+ import org .openstreetmap .josm .data .osm .DataSet ;
21+ import org .openstreetmap .josm .data .osm .Node ;
22+ import org .openstreetmap .josm .data .osm .Way ;
23+ import org .openstreetmap .josm .data .preferences .sources .ValidatorPrefHelper ;
24+ import org .openstreetmap .josm .gui .ExtendedDialog ;
25+ import org .openstreetmap .josm .gui .MainApplication ;
26+ import org .openstreetmap .josm .gui .layer .OsmDataLayer ;
927import org .openstreetmap .josm .testutils .JOSMTestRules ;
10-
11- import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
28+ import org .openstreetmap .josm .testutils .mockers .ExtendedDialogMocker ;
1229
1330/**
1431 * Unit tests for class {@link ValidateUploadHook}.
@@ -20,7 +37,7 @@ class ValidateUploadHookTest {
2037 */
2138 @ RegisterExtension
2239 @ SuppressFBWarnings (value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" )
23- public JOSMTestRules test = new JOSMTestRules ().fakeAPI ().timeout (30000 );
40+ public JOSMTestRules test = new JOSMTestRules ().main (). projection (). fakeAPI ().timeout (30000 );
2441
2542 /**
2643 * Test of {@link ValidateUploadHook#checkUpload} method.
@@ -29,4 +46,33 @@ class ValidateUploadHookTest {
2946 void testCheckUpload () {
3047 assertTrue (new ValidateUploadHook ().checkUpload (new APIDataSet ()));
3148 }
49+
50+ @ ParameterizedTest
51+ @ ValueSource (booleans = {true , false })
52+ void testUploadOtherErrors (boolean otherEnabled ) {
53+ ValidatorPrefHelper .PREF_OTHER_UPLOAD .put (otherEnabled );
54+ final DataSet ds = new DataSet ();
55+ final Way building = TestUtils .newWay ("building=yes" , new Node (new LatLon (33.2287665 , -111.8259225 )),
56+ new Node (new LatLon (33.2287335 , -111.8257513 )), new Node (new LatLon (33.2285316 , -111.8258086 )),
57+ new Node (new LatLon (33.2285696 , -111.8259781 )));
58+ ds .addPrimitiveRecursive (building );
59+ building .addNode (building .firstNode ());
60+ ds .addDataSource (new DataSource (new Bounds (33 , -112 , 34 , -111 ), "" ));
61+ MainApplication .getLayerManager ().addLayer (new OsmDataLayer (ds ,
62+ "ValidateUploadHookTest#testUploadOtherErrors" , null ));
63+ final ExtendedDialogMocker mocker =
64+ new ExtendedDialogMocker (Collections .singletonMap ("Suspicious data found. Upload anyway?" , "Cancel" )) {
65+ @ Override
66+ protected String getString (ExtendedDialog instance ) {
67+ return instance .getTitle ();
68+ }
69+
70+ @ Mock
71+ public void dispose () {
72+ // Do nothing
73+ }
74+ };
75+ new ValidateUploadHook ().checkUpload (new APIDataSet (ds ));
76+ assertEquals (!otherEnabled , mocker .getInvocationLog ().isEmpty ());
77+ }
3278}
0 commit comments