Ticket #21333: 21333.6.patch

File 21333.6.patch, 5.6 KB (added by taylor.smock, 5 years ago)

Fix unit tests

  • src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java b/src/org/openstreetmap/josm/data/validation/tests/SharpAngles.java
    index 676eb47f10..d476474051 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr;  
    55
    66import java.util.Arrays;
    77import java.util.Collection;
     8import java.util.Collections;
    89import java.util.TreeSet;
    910
    1011import org.openstreetmap.josm.data.coor.EastNorth;
    import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;  
    1617import org.openstreetmap.josm.data.validation.Severity;
    1718import org.openstreetmap.josm.data.validation.Test;
    1819import org.openstreetmap.josm.data.validation.TestError;
     20import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     21import org.openstreetmap.josm.spi.preferences.Config;
    1922import org.openstreetmap.josm.tools.Geometry;
    2023import org.openstreetmap.josm.tools.bugreport.BugReport;
    2124
    import org.openstreetmap.josm.tools.bugreport.BugReport;  
    2730public class SharpAngles extends Test {
    2831    private static final int SHARPANGLESCODE = 3800;
    2932    /** The code for a sharp angle */
    30     private static final int SHARP_ANGLES = SHARPANGLESCODE + 0;
    31     /** The maximum angle for sharp angles */
    32     private double maxAngle = 45.0; // degrees
    33     /** The length that at least one way segment must be shorter than */
    34     private double maxLength = 10.0; // meters
     33    private static final int SHARP_ANGLES = SHARPANGLESCODE;
     34    /** The maximum angle for sharp angles (degrees) */
     35    private double maxAngle;
     36    /** The length that at least one way segment must be shorter than (meters) */
     37    private double maxLength;
    3538    /** Specific highway types to ignore */
    36     private final Collection<String> ignoreHighways = new TreeSet<>(
    37             Arrays.asList("platform", "rest_area", "services", "via_ferrata"));
     39    private Collection<String> ignoreHighways = Collections.emptyList();
     40    /** Specific railway types to ignore */
     41    private Collection<String> ignoreRailway = Collections.emptyList();
    3842
    3943    /**
    4044     * Construct a new {@code IntersectionIssues} object
    4145     */
    4246    public SharpAngles() {
    43         super(tr("Sharp angles"), tr("Check for sharp angles on roads"));
     47        super(tr("Sharp angles"), tr("Check for sharp angles on man made transportation ways"));
     48    }
     49
     50    @Override
     51    public void startTest(ProgressMonitor progressMonitor) {
     52        super.startTest(progressMonitor);
     53        this.maxLength = Config.getPref().getDouble("validator.sharpangles.maxlength", 10.0); // meters
     54        this.maxAngle = Config.getPref().getDouble("validator.sharpangles.maxangle", 45.0); // degrees
     55        this.ignoreRailway = Collections.unmodifiableCollection(new TreeSet<>(
     56                Config.getPref().getList("validator.sharpangles.ignorerailway",
     57                        Arrays.asList("crossing_box", "loading_ramp", "platform", "roundhouse", "signal_box", "station",
     58                                "traverser", "wash", "workshop"))));
     59        // TODO make immutable when addIgnoredHighway is removed
     60        this.ignoreHighways = new TreeSet<>(
     61                Config.getPref().getList("validator.sharpangles.ignorehighway",
     62                        Arrays.asList("platform", "rest_area", "services", "via_ferrata"))
     63        );
    4464    }
    4565
    4666    @Override
    public class SharpAngles extends Test {  
    6181     * @return {@code true} if the way should be checked.
    6282     */
    6383    public boolean shouldBeTestedForSharpAngles(Way way) {
    64         return (way.hasKey("highway") && !way.hasTag("area", "yes") && !way.hasKey("via_ferrata_scale") &&
    65                 !ignoreHighways.contains(way.get("highway")));
     84        return !way.hasTag("area", "yes") &&
     85                ((way.hasKey("highway") && !way.hasKey("via_ferrata_scale") && !ignoreHighways.contains(way.get("highway")))
     86                    || (way.hasKey("railway") && !ignoreRailway.contains(way.get("railway"))));
    6687    }
    6788
    6889    /**
    public class SharpAngles extends Test {  
    139160    /**
    140161     * Add a highway to ignore
    141162     * @param highway The highway type to ignore (e.g., if you want to ignore residential roads, use "residential")
     163     * @since xxx (deprecated)
     164     * @deprecated Not known to be used. Please use config preference "validator.sharpangles.ignorehighway" instead.
    142165     */
     166    @Deprecated
    143167    public void addIgnoredHighway(String highway) {
     168        // Don't forget to make ignoreHighways immutable when this method is removed
    144169        ignoreHighways.add(highway);
    145170    }
    146171
  • test/unit/org/openstreetmap/josm/data/validation/tests/SharpAnglesTest.java

    diff --git a/test/unit/org/openstreetmap/josm/data/validation/tests/SharpAnglesTest.java b/test/unit/org/openstreetmap/josm/data/validation/tests/SharpAnglesTest.java
    index 72c177cbe1..c90d11bf6c 100644
    a b import org.openstreetmap.josm.TestUtils;  
    99import org.openstreetmap.josm.data.coor.LatLon;
    1010import org.openstreetmap.josm.data.osm.Node;
    1111import org.openstreetmap.josm.data.osm.Way;
     12import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1213import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    1314import org.openstreetmap.josm.testutils.annotations.Projection;
    1415
    class SharpAnglesTest {  
    2829    public void setUp() throws Exception {
    2930        angles = new SharpAngles();
    3031        angles.initialize();
     32        angles.startTest(NullProgressMonitor.INSTANCE);
    3133    }
    3234
    3335    /**