⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 beantest.java

📁 html to xml convertor
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        lb = (LinkBean)unpickle (data);        links2 = lb.getLinks ();        assertEquals ("Number of links after serialization differs", links.length, links2.length);        for (int i = 0; i < links.length; i++)        {            assertEquals (                "Links before and after serialization differ",                links[i],                links2[i]);        }    }    public void testStringBeanListener ()    {        final StringBean sb;        final Boolean hit[] = new Boolean[1];        sb = new StringBean ();        hit[0] = Boolean.FALSE;        sb.addPropertyChangeListener (            new PropertyChangeListener ()            {                public void propertyChange (PropertyChangeEvent event)                {                    if (event.getSource ().equals (sb))                        if (event.getPropertyName ().equals (StringBean.PROP_STRINGS_PROPERTY))                            hit[0] = Boolean.TRUE;                }            });        hit[0] = Boolean.FALSE;        sb.setURL ("http://htmlparser.sourceforge.net/test/example.html");        assertTrue (            "Strings property change not fired for URL change",            hit[0].booleanValue ());        hit[0] = Boolean.FALSE;        sb.setLinks (true);        assertTrue (            "Strings property change not fired for links change",            hit[0].booleanValue ());    }    public void testLinkBeanListener ()    {        final LinkBean lb;        final Boolean hit[] = new Boolean[1];        lb = new LinkBean ();        hit[0] = Boolean.FALSE;        lb.addPropertyChangeListener (            new PropertyChangeListener ()            {                public void propertyChange (PropertyChangeEvent event)                {                    if (event.getSource ().equals (lb))                        if (event.getPropertyName ().equals (LinkBean.PROP_LINKS_PROPERTY))                            hit[0] = Boolean.TRUE;                }            });        hit[0] = Boolean.FALSE;        lb.setURL ("http://htmlparser.sourceforge.net/test/example.html");        assertTrue (            "Links property change not fired for URL change",            hit[0].booleanValue ());    }    /**     * Test no text returns empty string.     */    public void testCollapsed1 ()    {        StringBean sb;        sb = new StringBean ();        sb.setLinks (false);        sb.setReplaceNonBreakingSpaces (true);        sb.setCollapse (false);        check (sb, "<html><head></head><body></body></html>", "");        check (sb, "<html><head></head><body> </body></html>", " ");        check (sb, "<html><head></head><body>\t</body></html>", "\t");        sb.setCollapse (true);        check (sb, "<html><head></head><body></body></html>", "");        check (sb, "<html><head></head><body> </body></html>", "");        check (sb, "<html><head></head><body>\t</body></html>", "");    }    /**     * Test multiple whitespace returns empty string.     */    public void testCollapsed2 ()    {        StringBean sb;        sb = new StringBean ();        sb.setLinks (false);        sb.setReplaceNonBreakingSpaces (true);        sb.setCollapse (false);        check (sb, "<html><head></head><body>  </body></html>", "  ");        check (sb, "<html><head></head><body>\t\t</body></html>", "\t\t");        check (sb, "<html><head></head><body> \t\t</body></html>", " \t\t");        check (sb, "<html><head></head><body>\t \t</body></html>", "\t \t");        check (sb, "<html><head></head><body>\t\t </body></html>", "\t\t ");        sb.setCollapse (true);        check (sb, "<html><head></head><body>  </body></html>", "");        check (sb, "<html><head></head><body>\t\t</body></html>", "");        check (sb, "<html><head></head><body> \t\t</body></html>", "");        check (sb, "<html><head></head><body>\t \t</body></html>", "");        check (sb, "<html><head></head><body>\t\t </body></html>", "");    }    /**     * Test text preceded or followed by whitespace returns just text.     */    public void testCollapsed3 ()    {        StringBean sb;        sb = new StringBean ();        sb.setLinks (false);        sb.setReplaceNonBreakingSpaces (true);        sb.setCollapse (false);        check (sb, "<html><head></head><body>x  </body></html>", "x  ");        check (sb, "<html><head></head><body>x\t\t</body></html>", "x\t\t");        check (sb, "<html><head></head><body>x \t\t</body></html>", "x \t\t");        check (sb, "<html><head></head><body>x\t \t</body></html>", "x\t \t");        check (sb, "<html><head></head><body>x\t\t </body></html>", "x\t\t ");        sb.setCollapse (true);        check (sb, "<html><head></head><body>x  </body></html>", "x");        check (sb, "<html><head></head><body>x\t\t</body></html>", "x");        check (sb, "<html><head></head><body>x \t\t</body></html>", "x");        check (sb, "<html><head></head><body>x\t \t</body></html>", "x");        check (sb, "<html><head></head><body>x\t\t </body></html>", "x");        check (sb, "<html><head></head><body>  x</body></html>", "x");        check (sb, "<html><head></head><body>\t\tx</body></html>", "x");        check (sb, "<html><head></head><body> \t\tx</body></html>", "x");        check (sb, "<html><head></head><body>\t \tx</body></html>", "x");        check (sb, "<html><head></head><body>\t\t x</body></html>", "x");    }    /**     * Test text including a "pre" tag     */    public void testOutputWithPreTags() {        StringBean sb;        sb = new StringBean ();        String sampleCode = "public class Product {}";        check (sb, "<body><pre>"+sampleCode+"</pre></body>", sampleCode);    }    /**     * Test text including a "script" tag     */    public void testOutputWithScriptTags() {        StringBean sb;        sb = new StringBean ();        String sampleScript =          "<script language=\"javascript\">\r\n"        + "if(navigator.appName.indexOf(\"Netscape\") != -1)\r\n"        + " document.write ('xxx');\r\n"        + "else\r\n"        + " document.write ('yyy');\r\n"        + "</script>\r\n";        check (sb, "<body>"+sampleScript+"</body>", "");    }    /*     * Test output with pre and any tag.     */    public void testOutputWithPreAndAnyTag()    {        StringBean sb;        sb = new StringBean ();        sb.setLinks (false);        sb.setReplaceNonBreakingSpaces (true);        sb.setCollapse (false);        check (sb, "<html><head></head><body><pre><hello></pre></body></html>", "");    }    /*     * Test output with pre and any tag and text.     */    public void testOutputWithPreAndAnyTagPlusText()    {        StringBean sb;        sb = new StringBean ();        sb.setLinks (false);        sb.setReplaceNonBreakingSpaces (true);        sb.setCollapse (false);        check (sb, "<html><head></head><body><pre><hello>dogfood</hello></pre></body></html>", "dogfood");    }    /*     * Test output with pre and any tag and text.     */    public void testOutputWithPreAndAnyTagPlusTextWithWhitespace()    {        StringBean sb;        sb = new StringBean ();        sb.setLinks (false);        sb.setReplaceNonBreakingSpaces (true);        sb.setCollapse (true);        check (sb, "<html><head></head><body><pre><hello>dog  food</hello></pre></body></html>", "dog  food");    }    /*     * Test output without pre and any tag and text.     */    public void testOutputWithoutPreAndAnyTagPlusTextWithWhitespace()    {        StringBean sb;        sb = new StringBean ();        sb.setLinks (false);        sb.setReplaceNonBreakingSpaces (true);        sb.setCollapse (true);        check (sb, "<html><head></head><body><hello>dog  food</hello></body></html>", "dog food");    }    /**     * Test output with pre and script tags     */    public void xtestOutputWithPreAndScriptTags ()    {        StringBean sb;        sb = new StringBean ();        String sampleScript =          "<script language=\"javascript\">\r\n"        + "if(navigator.appName.indexOf(\"Netscape\") != -1)\r\n"        + " document.write ('xxx');\r\n"        + "else\r\n"        + " document.write ('yyy');\r\n"        + "</script>\r\n";        check (sb, "<body><pre>"+sampleScript+"</pre></body>", sampleScript);    }    /**     * Test output with non-breaking tag within text.     */    public void testTagWhitespace ()    {        StringBean sb;        sb = new StringBean ();        String pre = "AAAAA BBBBB AAA";        String mid = "AA";        String post = " BBBBB";        String html =          "<HTML>\r\n"        + "<body>\r\n"        + "<p>" + pre + "<font color='red'>" + mid + "</font>" + post + "</p>\r\n"        + "</body>\r\n"        + "</HTML>\r\n";        check (sb, html, pre + mid + post);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -