Esempio n. 1
0
  @Test
  public void clone_Deep() {
    // Arrange
    AnchorElement child = Document.get().createAnchorElement();
    child.setInnerText("child inner text");
    child.getStyle().setBackgroundColor("black");
    n.appendChild(child);

    // Act
    DivElement newNode = n.cloneNode(true).cast();

    // Assert
    assertEquals(Node.ELEMENT_NODE, newNode.getNodeType());
    DivElement source = n.cast();
    assertEquals(source.getInnerText(), newNode.getInnerText());
    assertEquals(source.getInnerHTML(), newNode.getInnerHTML());
    assertEquals(source.toString(), newNode.toString());

    assertNull(newNode.getParentNode());
    assertEquals(n.getChildNodes().getLength(), newNode.getChildNodes().getLength());

    assertEquals(Node.ELEMENT_NODE, newNode.getChildNodes().getItem(0).getNodeType());
    AnchorElement childElement = newNode.getChildNodes().getItem(0).cast();
    assertEquals("child inner text", childElement.getInnerText());

    Style newStyle = childElement.getStyle();
    assertTrue(newStyle != child.getStyle());
    assertEquals("black", newStyle.getBackgroundColor());
  }
Esempio n. 2
0
  @Test
  public void clone_NotDeep() {
    // Arrange
    Element e = n.cast();
    e.setInnerText("text");
    e.getStyle().setBackgroundColor("black");

    AnchorElement child = Document.get().createAnchorElement();
    child.setInnerText("child inner text");
    n.appendChild(child);

    // Act
    DivElement newNode = n.cloneNode(false).cast();

    // Assert
    assertEquals(Node.ELEMENT_NODE, newNode.getNodeType());
    assertTrue(e.getStyle() != newNode.getStyle());
    assertEquals("black", newNode.getStyle().getBackgroundColor());
    assertEquals("text", newNode.getInnerText());
    assertNull(newNode.getParentNode());
    assertEquals(2, n.getChildNodes().getLength());
    assertEquals(1, newNode.getChildNodes().getLength());
  }