test.com.generationjava.web.HtmlWTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gj-scrape Show documentation
Show all versions of gj-scrape Show documentation
Simple scraping component of GenJava-Core.
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" ) );
}
}