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

test.com.generationjava.web.XmlWTest 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 XmlWTest extends TestCase {

    private String testXml = "test";

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

    //-----------------------------------------------------------------------
    // To test: 
    //     XmlW.escapeXml
    //     XmlW.unescapeXml
    //     XmlW.getContent

    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, XmlW.escapeXml( 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, XmlW.unescapeXml( toUnescape ) );
    }

    public void testSymmetry() {
        String expected = "4 is < 7 & 7 is > 4 but \"7\" and '4' make error. ";
        assertEquals( expected, XmlW.unescapeXml( XmlW.escapeXml( expected ) ) );
    }

    public void testRemove() {
        assertEquals( "FOO", XmlW.removeXml("FOO") );
        assertEquals( "FOO", XmlW.removeXml("FOO") );
        assertEquals( "FOO", XmlW.removeXml("FOO") );
        assertEquals( "FOO", XmlW.removeXml("FOO") );
        assertEquals( "some comment", XmlW.removeXml("

some comment

") ); assertEquals( "", XmlW.removeXml("") ); } public void testGetAttribute() { assertEquals( "foo", XmlW.getAttribute( this.testXml, "thing" ) ); } public void testGetIndexOpeningTag() { assertEquals( 0, XmlW.getIndexOpeningTag(this.testXml, "bar") ); } public void testGetIndexClosingTag() { assertEquals( 36, XmlW.getIndexClosingTag(this.testXml, "bar") ); } public void testGetContent() { assertEquals( "test", XmlW.getContent(this.testXml, "bar") ); } public void testSingleQuoteAttribute() { assertEquals( "single", XmlW.getAttribute(this.testXml, "other" ) ); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy