You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.3 KiB
74 lines
2.3 KiB
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<String, String> htmlCharacterMap = new HashMap<String, String>(){ |
|
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 = "<br>this is a test<br>"; |
|
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 = "<br>this is a test<br>"; |
|
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); |
|
} |
|
}
|
|
|