// Test for [JACKSON-631]
  public void testBase64Text() throws Exception {
    // let's actually iterate over sets of encoding modes, lengths

    final int[] LENS = {1, 2, 3, 4, 7, 9, 32, 33, 34, 35};
    final Base64Variant[] VARIANTS = {
      Base64Variants.MIME,
      Base64Variants.MIME_NO_LINEFEEDS,
      Base64Variants.MODIFIED_FOR_URL,
      Base64Variants.PEM
    };

    for (int len : LENS) {
      byte[] input = new byte[len];
      for (int i = 0; i < input.length; ++i) {
        input[i] = (byte) i;
      }
      for (Base64Variant variant : VARIANTS) {
        TextNode n = new TextNode(variant.encode(input));
        byte[] data = null;
        try {
          data = n.getBinaryValue(variant);
        } catch (Exception e) {
          throw new IOException(
              "Failed (variant " + variant + ", data length " + len + "): " + e.getMessage());
        }
        assertNotNull(data);
        assertArrayEquals(data, input);
      }
    }
  }
示例#2
0
  @Test
  public void insertChildrenAtPosition() {
    Document doc =
        Jsoup.parse(
            "<div id=1>Text1 <p>One</p> Text2 <p>Two</p></div><div id=2>Text3 <p>Three</p></div>");
    Element div1 = doc.select("div").get(0);
    Elements p1s = div1.select("p");
    Element div2 = doc.select("div").get(1);

    assertEquals(2, div2.childNodeSize());
    div2.insertChildren(-1, p1s);
    assertEquals(2, div1.childNodeSize()); // moved two out
    assertEquals(4, div2.childNodeSize());
    assertEquals(3, p1s.get(1).siblingIndex()); // should be last

    List<Node> els = new ArrayList<Node>();
    Element el1 = new Element(Tag.valueOf("span"), "").text("Span1");
    Element el2 = new Element(Tag.valueOf("span"), "").text("Span2");
    TextNode tn1 = new TextNode("Text4", "");
    els.add(el1);
    els.add(el2);
    els.add(tn1);

    assertNull(el1.parent());
    div2.insertChildren(-2, els);
    assertEquals(div2, el1.parent());
    assertEquals(7, div2.childNodeSize());
    assertEquals(3, el1.siblingIndex());
    assertEquals(4, el2.siblingIndex());
    assertEquals(5, tn1.siblingIndex());
  }