@Test
public void testElementOrdering() throws Exception {

    final String test = "<html><head><title>Title</title>" +
            "<meta http-equiv=\"content-type\" content=\"text/html\">" +
            "<link rel=\"next\" href=\"next.html\" />" +
            "</head><body><p>Simple Content</p></body></html>";
    StringWriter sw = new StringWriter();
    new HtmlParser().parse(
            new ByteArrayInputStream(test.getBytes(UTF_8)),
            makeHtmlTransformer(sw), new Metadata(), new ParseContext());
    String result = sw.toString();
    // Title element in <head> section
    assertTrue(Pattern.matches("(?s)<html.*<head>.*<title>Title</title>.*</head>.*$", result));
    // No meta elements in body
    assertFalse(Pattern.matches("(?s).*<body>.*<meta. *</body>.*$", result));
    // meta elements should show up in <head> section
    assertTrue(Pattern.matches("(?s)<html.*<head>.*<meta .*</head>.*$", result));
    // No link elements in body
    assertFalse(Pattern.matches("(?s).*<body>.*<link .*</body>.*$", result));
    // link element should be in <head> section
    assertTrue(Pattern.matches("(?s)<html.*<head>.*<link .*</head>.*$", result));
    // There should be ending elements.
    assertTrue(Pattern.matches("(?s).*</body>.*</html>$", result));
}