Ticket #23008: 23008.patch

File 23008.patch, 5.0 KB (added by taylor.smock, 3 years ago)

Add ocean tests

  • test/unit/org/openstreetmap/josm/data/validation/tests/PowerLinesTest.java

    Subject: [PATCH] #23008
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/test/unit/org/openstreetmap/josm/data/validation/tests/PowerLinesTest.java b/test/unit/org/openstreetmap/josm/data/validation/tests/PowerLinesTest.java
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.validation.tests;
    33
     4import static org.junit.jupiter.api.Assertions.assertAll;
    45import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
     6import static org.junit.jupiter.api.Assertions.assertEquals;
    57import static org.junit.jupiter.api.Assertions.assertFalse;
     8import static org.junit.jupiter.api.Assertions.assertInstanceOf;
     9import static org.junit.jupiter.api.Assertions.assertSame;
    610import static org.junit.jupiter.api.Assertions.assertTrue;
    711
     12import java.util.ArrayList;
     13
    814import org.junit.jupiter.api.BeforeEach;
    915import org.junit.jupiter.api.Test;
    1016import org.openstreetmap.josm.TestUtils;
     
    1521import org.openstreetmap.josm.data.osm.RelationMember;
    1622import org.openstreetmap.josm.data.osm.TagMap;
    1723import org.openstreetmap.josm.data.osm.Way;
     24import org.openstreetmap.josm.data.osm.WaySegment;
     25import org.openstreetmap.josm.data.validation.TestError;
     26import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1827import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    1928import org.openstreetmap.josm.testutils.annotations.Projection;
    2029
     
    129138                new RelationMember("", TestUtils.newWay("", new Node(), new Node())));
    130139        assertDoesNotThrow(() -> this.powerLines.visit(powerLine));
    131140    }
     141
     142    @Test
     143    void testOceanBad() {
     144        final Way bottom = TestUtils.newWay("natural=coastline", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 1)));
     145        final Way top = TestUtils.newWay("natural=coastline", new Node(new LatLon(0.001, 1)), new Node(new LatLon(0.001, 0)));
     146        final Way powerline = TestUtils.newWay("power=minor_line",
     147                new Node(new LatLon(-0.00135, 0.5)),
     148                new Node(new LatLon(-0.0013, 0.5)),
     149                new Node(new LatLon(-0.00125, 0.5)),
     150                new Node(new LatLon(0.00125, 0.5)),
     151                new Node(new LatLon(0.0013, 0.5)),
     152                new Node(new LatLon(0.00135, 0.5)));
     153        ds.addPrimitiveRecursive(top);
     154        ds.addPrimitiveRecursive(bottom);
     155        ds.addPrimitiveRecursive(powerline);
     156        for (Node node : powerline.getNodes()) {
     157            node.put("power", "pole");
     158        }
     159
     160        this.powerLines.startTest(NullProgressMonitor.INSTANCE);
     161        this.powerLines.visit(new ArrayList<>(ds.getWays()));
     162        this.powerLines.endTest();
     163        assertEquals(1, this.powerLines.getErrors().size());
     164        final TestError testError = this.powerLines.getErrors().get(0);
     165        assertAll(() -> assertEquals("Possibly missing line support node within power line", testError.getMessage()),
     166                () -> assertEquals(2, testError.getPrimitives().size()),
     167                () -> assertTrue(testError.getPrimitives().contains(powerline.getNode(2))),
     168                () -> assertTrue(testError.getPrimitives().contains(powerline.getNode(3))),
     169                () -> assertEquals(1, testError.getHighlighted().size()));
     170        final WaySegment segment = assertInstanceOf(WaySegment.class, testError.getHighlighted().iterator().next());
     171        assertAll(() -> assertSame(powerline, segment.getWay()),
     172                () -> assertEquals(2, segment.getLowerIndex()),
     173                () -> assertEquals(3, segment.getUpperIndex()));
     174    }
     175
     176    @Test
     177    void testOceanGood() {
     178        final Way bottom = TestUtils.newWay("natural=coastline", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 1)));
     179        final Way top = TestUtils.newWay("natural=coastline", new Node(new LatLon(0.001, 1)), new Node(new LatLon(0.001, 0)));
     180        final Way powerline = TestUtils.newWay("power=minor_line",
     181                new Node(new LatLon(-0.003, 0.5)),
     182                new Node(new LatLon(-0.002, 0.5)),
     183                new Node(new LatLon(-0.001, 0.5)),
     184                new Node(new LatLon(0.001, 0.5)),
     185                new Node(new LatLon(0.002, 0.5)),
     186                new Node(new LatLon(0.003, 0.5)));
     187        ds.addPrimitiveRecursive(top);
     188        ds.addPrimitiveRecursive(bottom);
     189        ds.addPrimitiveRecursive(powerline);
     190        for (Node node : powerline.getNodes()) {
     191            node.put("power", "pole");
     192        }
     193
     194        this.powerLines.startTest(NullProgressMonitor.INSTANCE);
     195        this.powerLines.visit(new ArrayList<>(ds.getWays()));
     196        this.powerLines.endTest();
     197        assertTrue(this.powerLines.getErrors().isEmpty());
     198    }
    132199}