package de.superx.util; import static org.junit.Assert.*; import java.util.HashMap; import java.util.Map; import org.junit.Test; /** * Class to test {@link de.superx.util.HtmlUtils} * @author hiber */ public class HtmlUtilsTest { @SuppressWarnings("static-method") @Test public void testHtmlEscape() { Map htmlCharacterMap = new HashMap(){ private static final long serialVersionUID = 7859987043106055919L; { put("<", "<"); put(">", ">"); put("&", "&"); } }; for(String htmlCharacter : htmlCharacterMap.keySet()) { assertEquals("Html character escaped correctly", htmlCharacterMap.get(htmlCharacter), HtmlUtils.htmlEscape(htmlCharacter)); } } @SuppressWarnings("static-method") @Test public void testAdaptWithStringBuffer() { String testString = "\nthis is a test\n"; StringBuffer testStringBuffer = new StringBuffer(testString); String expectedString = "
this is a test
"; assertEquals("Java escapes has been transformed", expectedString, HtmlUtils.adapt(testStringBuffer)); } @SuppressWarnings("static-method") @Test public void testAdaptWithString() { String testString = "\nthis is a test\n"; String expectedString = "
this is a test
"; assertEquals("Java escapes has been transformed", expectedString, HtmlUtils.adapt(testString)); } @SuppressWarnings("static-method") @Test public void testChooseName() { String varname = "testVar"; String captionShort = null; assertEquals("method returns value of variable 'varname'", varname, HtmlUtils.chooseName(varname, captionShort)); captionShort = ""; assertEquals("method returns value of variable 'varname'", varname, HtmlUtils.chooseName(varname, captionShort)); captionShort = "null"; assertEquals("method returns value of variable 'varname'", varname, HtmlUtils.chooseName(varname, captionShort)); captionShort = "testCaption"; assertEquals("method returns value of variable 'captionShort'", captionShort, HtmlUtils.chooseName(varname, captionShort)); } @SuppressWarnings("static-method") @Test public void testEncodeURL() { String testUrl = "https://www.his.de"; assertEquals("method returns the value of the passed variable(...)", HtmlUtils.encodeURL(testUrl, null), testUrl); } }