src/test/java/de/blau/android/osm/BasicStuffTest.java
/**
     * Remove a node from a degenerate (two node) way
     */
Remove a node from a degenerate (two node) way
Remove a node from a degenerate ( two node ) way
@Test
    public void deleteNodeFromDegenerateWay() {
        try {
            final CountDownLatch signal = new CountDownLatch(1);
            Logic logic = App.getLogic();
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            InputStream is = loader.getResourceAsStream("closedways.osm");
            logic.readOsmFile(ApplicationProvider.getApplicationContext(), is, false, new SignalHandler(signal));
            try {
                signal.await(ApiTest.TIMEOUT, TimeUnit.SECONDS); 
            } catch (InterruptedException e) { 
                Assert.fail(e.getMessage());
            }
            StorageDelegator delegator = App.getDelegator();
            Way way0 = (Way) delegator.getOsmElement(Way.NAME, 1544L);
            Assert.assertNotNull(way0);
            Assert.assertEquals(1, way0.getNodes().size());
            delegator.removeNode(way0.getFirstNode());
            Assert.assertNotNull(way0);
            Assert.assertEquals(OsmElement.STATE_DELETED, way0.getState());
            Way way1 = (Way) delegator.getOsmElement(Way.NAME, 1545L);
            Assert.assertNotNull(way1);
            Assert.assertEquals(5, way1.getNodes().size());
            Node node1 = (Node) delegator.getOsmElement(Node.NAME, 296055259L);
            Assert.assertNotNull(node1);
            delegator.removeNode(node1);
            Assert.assertNotNull(way1);
            Assert.assertEquals(OsmElement.STATE_DELETED, way1.getState());
            Node node2 = (Node) delegator.getOsmElement(Node.NAME, 289987511L);
            Assert.assertNotNull(node2);
            Assert.assertEquals(OsmElement.STATE_UNCHANGED, node2.getState());
            Way way2 = (Way) delegator.getOsmElement(Way.NAME, 1546L);
            Assert.assertNotNull(way2);
            Assert.assertEquals(7, way2.getNodes().size());
            node1 = (Node) delegator.getOsmElement(Node.NAME, 296055272L);
            Assert.assertNotNull(node1);
            delegator.removeNode(node1);
            Assert.assertNotNull(way2);
            Assert.assertEquals(OsmElement.STATE_MODIFIED, way2.getState());
            Assert.assertEquals(4, way2.getNodes().size());
            delegator.removeNode(way2.getFirstNode());
            Assert.assertNotNull(way2);
            Assert.assertEquals(OsmElement.STATE_DELETED, way2.getState());
        } catch (Exception igit) {
            Assert.fail(igit.getMessage());
        }
    }
@ Test public void deleteNodeFromDegenerateWay ( ) { try { final CountDownLatch signal = new CountDownLatch ( 1 ) ; Logic logic = App . getLogic ( ) ; ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; InputStream is = loader . getResourceAsStream ( "closedways.osm" ) ; logic . readOsmFile ( ApplicationProvider . getApplicationContext ( ) , is , false , new SignalHandler ( signal ) ) ; try { signal . await ( ApiTest . TIMEOUT , TimeUnit . SECONDS ) ; } catch ( InterruptedException e ) { Assert . fail ( e . getMessage ( ) ) ; } StorageDelegator delegator = App . getDelegator ( ) ; Way way0 = ( Way ) delegator . getOsmElement ( Way . NAME , 1544L ) ; Assert . assertNotNull ( way0 ) ; Assert . assertEquals ( 1 , way0 . getNodes ( ) . size ( ) ) ; delegator . removeNode ( way0 . getFirstNode ( ) ) ; Assert . assertNotNull ( way0 ) ; Assert . assertEquals ( OsmElement . STATE_DELETED , way0 . getState ( ) ) ; Way way1 = ( Way ) delegator . getOsmElement ( Way . NAME , 1545L ) ; Assert . assertNotNull ( way1 ) ; Assert . assertEquals ( 5 , way1 . getNodes ( ) . size ( ) ) ; Node node1 = ( Node ) delegator . getOsmElement ( Node . NAME , 296055259L ) ; Assert . assertNotNull ( node1 ) ; delegator . removeNode ( node1 ) ; Assert . assertNotNull ( way1 ) ; Assert . assertEquals ( OsmElement . STATE_DELETED , way1 . getState ( ) ) ; Node node2 = ( Node ) delegator . getOsmElement ( Node . NAME , 289987511L ) ; Assert . assertNotNull ( node2 ) ; Assert . assertEquals ( OsmElement . STATE_UNCHANGED , node2 . getState ( ) ) ; Way way2 = ( Way ) delegator . getOsmElement ( Way . NAME , 1546L ) ; Assert . assertNotNull ( way2 ) ; Assert . assertEquals ( 7 , way2 . getNodes ( ) . size ( ) ) ; node1 = ( Node ) delegator . getOsmElement ( Node . NAME , 296055272L ) ; Assert . assertNotNull ( node1 ) ; delegator . removeNode ( node1 ) ; Assert . assertNotNull ( way2 ) ; Assert . assertEquals ( OsmElement . STATE_MODIFIED , way2 . getState ( ) ) ; Assert . assertEquals ( 4 , way2 . getNodes ( ) . size ( ) ) ; delegator . removeNode ( way2 . getFirstNode ( ) ) ; Assert . assertNotNull ( way2 ) ; Assert . assertEquals ( OsmElement . STATE_DELETED , way2 . getState ( ) ) ; } catch ( Exception igit ) { Assert . fail ( igit . getMessage ( ) ) ; } }
Remove a node from a degenerate (two node) way
Remove a node from a degenerate ( two node ) way
// NOSONAR // NOSONAR // 2 node closed way, 1 node will silently get deleted when parsing // 3(+2) node closed way // 5(+2) node closed way with 2x2 the same node