src/test/java/de/blau/android/osm/StorageDelegatorTest.java
/**
     * As above but start at the beginning of the way
     */
As above but start at the beginning of the way
As above but start at the beginning of the way
@Test
    public void removeEndNodeFromWay2() {
        StorageDelegator d = new StorageDelegator();
        Way w = DelegatorUtil.addWayToStorage(d, false);
        Way temp = (Way) d.getOsmElement(Way.NAME, w.getOsmId());
        assertNotNull(temp);
        Node tempNode = temp.getNodes().get(2);
        Map<String, String> tags = new TreeMap<>();
        tags.put("test", "test");
        tempNode.setTags(tags);
        int count = temp.nodeCount();
        assertEquals(4, count);
        final Storage apiStorage = d.getApiStorage();
        for (int i = 0; i < 2; i++) {
            Node n = temp.getFirstNode();
            d.removeEndNodeFromWay(false, temp, !n.isTagged());
            assertFalse(temp.hasNode(n));
            assertEquals(count - (i + 1), temp.nodeCount());
            assertNotNull(apiStorage.getWay(temp.getOsmId()));
        }
        Node n = temp.getFirstNode();
        d.removeEndNodeFromWay(false, temp, !n.isTagged());
        assertEquals(OsmElement.STATE_DELETED, temp.getState());
        assertNull(apiStorage.getOsmElement(Way.NAME, temp.getOsmId()));
        assertEquals(OsmElement.STATE_CREATED, tempNode.getState());
    }
@ Test public void removeEndNodeFromWay2 ( ) { StorageDelegator d = new StorageDelegator ( ) ; Way w = DelegatorUtil . addWayToStorage ( d , false ) ; Way temp = ( Way ) d . getOsmElement ( Way . NAME , w . getOsmId ( ) ) ; assertNotNull ( temp ) ; Node tempNode = temp . getNodes ( ) . get ( 2 ) ; Map < String , String > tags = new TreeMap < > ( ) ; tags . put ( "test" , "test" ) ; tempNode . setTags ( tags ) ; int count = temp . nodeCount ( ) ; assertEquals ( 4 , count ) ; final Storage apiStorage = d . getApiStorage ( ) ; for ( int i = 0 ; i < 2 ; i ++ ) { Node n = temp . getFirstNode ( ) ; d . removeEndNodeFromWay ( false , temp , ! n . isTagged ( ) ) ; assertFalse ( temp . hasNode ( n ) ) ; assertEquals ( count - ( i + 1 ) , temp . nodeCount ( ) ) ; assertNotNull ( apiStorage . getWay ( temp . getOsmId ( ) ) ) ; } Node n = temp . getFirstNode ( ) ; d . removeEndNodeFromWay ( false , temp , ! n . isTagged ( ) ) ; assertEquals ( OsmElement . STATE_DELETED , temp . getState ( ) ) ; assertNull ( apiStorage . getOsmElement ( Way . NAME , temp . getOsmId ( ) ) ) ; assertEquals ( OsmElement . STATE_CREATED , tempNode . getState ( ) ) ; }
As above but start at the beginning of the way
As above but start at the beginning of the way
// removing the 2nd last node should delete the way // check that the tagged node is still here