All Downloads are FREE. Search and download functionalities are using the official Maven repository.

test.com.generationjava.web.HtmlWTest Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package com.generationjava.web;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

public class HtmlWTest extends TestCase {

    private String testHtml = "test";

    public HtmlWTest(String name) {
        super(name);
    }

    public void testEscape() {
        String toEscape = "4 is < 7 & 7 is > 4 but \"7\" and '4' make error. ";
        String expected = "4 is < 7 & 7 is > 4 but "7" and '4' make error. ";
        assertEquals( expected, HtmlW.escapeHtml( toEscape ) );
    }

    /*
    public void testUnescape() {
        String toUnescape = "4 is < 7 & 7 is > 4 but "7" and '4' make error. ";
        String expected = "4 is < 7 & 7 is > 4 but \"7\" and '4' make error. ";
        assertEquals( expected, HtmlW.unescapeHtml( toUnescape ) );
    }

    public void testSymmetry() {
        String expected = "4 is < 7 & 7 is > 4 but \"7\" and '4' make error. ";
        assertEquals( expected, HtmlW.unescapeHtml( HtmlW.escapeHtml( expected ) ) );
    }
    */

    public void testGetAttribute() {
        assertEquals( "foo", HtmlW.getAttribute( this.testHtml, "thing" ) );
        assertEquals( "foo", HtmlW.getAttribute( this.testHtml, "Thing" ) );
    }

    public void testGetIndexOpeningTag() {
        assertEquals( 0, HtmlW.getIndexOpeningTag(this.testHtml, "bar") );
        assertEquals( 0, HtmlW.getIndexOpeningTag(this.testHtml, "BAR") );
    }

    public void testGetIndexClosingTag() {
        assertEquals( 36, HtmlW.getIndexClosingTag(this.testHtml, "bar") );
        assertEquals( 36, HtmlW.getIndexClosingTag(this.testHtml, "bAR") );
    }

    public void testGetContent() {
        assertEquals( "test", HtmlW.getContent(this.testHtml, "bar") );
        assertEquals( "test", HtmlW.getContent(this.testHtml, "bAr") );
    }

    public void testSingleQuoteAttribute() {
        assertEquals( "single", HtmlW.getAttribute(this.testHtml, "other" ) );
        assertEquals( "single", HtmlW.getAttribute(this.testHtml, "oTHer" ) );
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy