Ignore:
Timestamp:
2020-11-30T10:57:50+01:00 (3 years ago)
Author:
GerdP
Message:

fix issues reported by sonar / coverity, simplify code, add unit tests to improve coverage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/DuplicateNodeTest.java

    r17275 r17376  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
    5 
     5import static org.junit.jupiter.api.Assertions.assertFalse;
     6import static org.junit.jupiter.api.Assertions.assertNotNull;
     7import static org.junit.jupiter.api.Assertions.assertTrue;
     8
     9import org.junit.jupiter.api.Test;
    610import org.junit.jupiter.api.extension.RegisterExtension;
    7 import org.junit.jupiter.api.Test;
     11import org.openstreetmap.josm.command.Command;
    812import org.openstreetmap.josm.data.coor.LatLon;
    913import org.openstreetmap.josm.data.osm.DataSet;
     
    4448        assertEquals(code, error.getCode());
    4549        assertEquals(fixable, error.isFixable());
     50        if (fixable) {
     51            Command c = error.getFix();
     52            assertNotNull(c);
     53            c.executeCommand();
     54            assertFalse(error.isFixable());
     55            c.undoCommand();
     56            assertTrue(error.isFixable());
     57            error.getPrimitives().iterator().next().setDeleted(true);
     58            if (error.getPrimitives().size() == 2) {
     59                assertFalse(error.isFixable());
     60            } else {
     61                assertTrue(error.isFixable());
     62            }
     63            error.getPrimitives().iterator().next().setDeleted(false);
     64        }
    4665    }
    4766
     
    6786
    6887    /**
     88     * Test of "Duplicate node" validation test - no duplicate
     89     */
     90    @Test
     91    void testNoDuplicateNode() {
     92        DataSet ds = new DataSet();
     93
     94        Node a = new Node(new LatLon(10.0, 5.0));
     95        Node b = new Node(new LatLon(10.0, 6.0));
     96        ds.addPrimitive(a);
     97        ds.addPrimitive(b);
     98
     99        a.put("foo", "bar");
     100        b.put("bar", "foo");
     101
     102        TEST.startTest(NullProgressMonitor.INSTANCE);
     103        TEST.visit(ds.allPrimitives());
     104        TEST.endTest();
     105
     106        assertEquals(0, TEST.getErrors().size());
     107    }
     108
     109    /**
     110     * Test of "Duplicate node" validation test - same position, with ele value
     111     */
     112    @Test
     113    void testDuplicateNodeWithEle() {
     114        DataSet ds = new DataSet();
     115
     116        Node a = new Node(new LatLon(10.0, 5.0));
     117        Node b = new Node(new LatLon(10.0, 5.0));
     118        ds.addPrimitive(a);
     119        ds.addPrimitive(b);
     120
     121        a.put("foo", "bar");
     122        b.put("bar", "foo");
     123        a.put("ele", "100");
     124        b.put("ele", "100");
     125
     126        TEST.startTest(NullProgressMonitor.INSTANCE);
     127        TEST.visit(ds.allPrimitives());
     128        TEST.endTest();
     129
     130        assertEquals(1, TEST.getErrors().size());
     131
     132        b.put("ele", "110");
     133
     134        TEST.startTest(NullProgressMonitor.INSTANCE);
     135        TEST.visit(ds.allPrimitives());
     136        TEST.endTest();
     137
     138        assertEquals(0, TEST.getErrors().size());
     139    }
     140
     141    /**
     142     * Test of "Duplicate node" validation test - three nodes
     143     */
     144    @Test
     145    void testDuplicateNodeTriple() {
     146        DataSet ds = new DataSet();
     147   
     148        Node a = new Node(new LatLon(10.0, 5.0));
     149        Node b = new Node(new LatLon(10.0, 5.0));
     150        Node c = new Node(new LatLon(10.0, 5.0));
     151        ds.addPrimitive(a);
     152        ds.addPrimitive(b);
     153        ds.addPrimitive(c);
     154   
     155        performTest(DuplicateNode.DUPLICATE_NODE_OTHER, ds, true);
     156        a.put("foo", "bar");
     157        b.put("foo", "bar");
     158        performTest(DuplicateNode.DUPLICATE_NODE_OTHER, ds, true);
     159    }
     160
     161    /**
    69162     * Test of "Duplicate node" validation test - different tag sets.
    70163     */
Note: See TracChangeset for help on using the changeset viewer.