/**
   * my and their way have no ids, nodes they refer to have an id. but my and their way are
   * semantically equal. so technical attributes of their way can be merged on my way. No conflict.
   */
  @Test
  public void waySimple_twoWaysWithNoId_NodesWithId() {

    // -- my data set

    Node n1 = new Node(new LatLon(0, 0));
    n1.setOsmId(1, 1);
    my.addPrimitive(n1);

    Node n2 = new Node(new LatLon(1, 1));
    n2.setOsmId(2, 1);
    my.addPrimitive(n2);

    Way myWay = new Way();
    myWay.addNode(n1);
    myWay.addNode(n2);
    my.addPrimitive(myWay);

    // -- their data set

    Node n3 = new Node(new LatLon(0, 0));
    n3.setOsmId(1, 1);
    their.addPrimitive(n3);

    Node n4 = new Node(new LatLon(1, 1));
    n4.setOsmId(2, 1);
    their.addPrimitive(n4);

    Way theirWay = new Way();
    theirWay.addNode(n3);
    theirWay.addNode(n4);
    User user = User.createOsmUser(1111, "their");
    theirWay.setUser(user);
    theirWay.setTimestamp(new Date());
    their.addPrimitive(theirWay);

    DataSetMerger visitor = new DataSetMerger(my, their);
    visitor.merge();

    // -- tests
    Way merged = (Way) my.getWays().toArray()[0];
    assertEquals(0, visitor.getConflicts().size());
    assertEquals("their", merged.getUser().getName());
    assertEquals(1111, merged.getUser().getId());
    assertEquals(theirWay.getRawTimestamp(), merged.getRawTimestamp());
    assertSame(merged, myWay);
    assertSame(merged.getNode(0), n1);
    assertSame(merged.getNode(1), n2);

    assertFalse(merged.isModified());
  }
  /**
   * My dataset includes a deleted node. Their dataset includes a way with three nodes, the first
   * one being my node.
   *
   * <p>=> the merged way should include all three nodes. Deleted node should have deleted=false and
   * special conflict with isDeleted should exist
   */
  @Test
  public void wayComplex_mergingADeletedNode() {

    // -- my dataset

    Node mn1 = new Node(new LatLon(0, 0));
    mn1.setOsmId(1, 1);
    mn1.setDeleted(true);
    my.addPrimitive(mn1);

    Node tn1 = new Node(new LatLon(0, 0));
    tn1.setOsmId(1, 1);
    their.addPrimitive(tn1);

    Node tn2 = new Node(new LatLon(1, 1));
    tn2.setOsmId(2, 1);
    their.addPrimitive(tn2);

    Node tn3 = new Node(new LatLon(2, 2));
    tn3.setOsmId(3, 1);
    their.addPrimitive(tn3);

    // -- their data set
    Way theirWay = new Way();
    theirWay.setOsmId(4, 1);
    theirWay.addNode(tn1);
    theirWay.addNode(tn2);
    theirWay.addNode(tn3);
    theirWay.setUser(User.createOsmUser(1111, "their"));
    theirWay.setTimestamp(new Date());
    their.addPrimitive(theirWay);

    DataSetMerger visitor = new DataSetMerger(my, their);
    visitor.merge();

    assertEquals(1, visitor.getConflicts().size());
    assertTrue(visitor.getConflicts().get(0).isMyDeleted());

    Way myWay = (Way) my.getPrimitiveById(4, OsmPrimitiveType.WAY);
    assertEquals(3, myWay.getNodesCount());

    Node n = (Node) my.getPrimitiveById(1, OsmPrimitiveType.NODE);
    assertTrue(myWay.getNodes().contains(n));

    assertFalse(myWay.isModified());
  }