📄 testcdata.java
字号:
cdata.append(text);
assertEquals("incorrect CDATA text", otherString + text, cdata.getText());
cdata.append(nullString);
assertEquals("incorrect CDATA text", otherString + text, cdata.getText());
cdata.append(specialCharactersText);
assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
cdata.append(nullString);
assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
cdata.append(emptyString);
assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
try {
cdata.append(cdataEndText);
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set it to the null (after it was set to another string so that we
// are sure comething has changed)
final CDATA cdata = new CDATA(nullString);
assertEquals("incorrect CDATA text", "", cdata.getText());
cdata.append(specialCharactersText);
assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
cdata.append(nullString);
assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
cdata.append(text);
assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
cdata.append(nullString);
assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
cdata.append(emptyString);
assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
cdata.append(otherString);
assertEquals("incorrect CDATA text", specialCharactersText + text + otherString, cdata.getText());
try {
cdata.append(cdataEndText);
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set it to the null (after it was set to another string so that we
// are sure comething has changed)
final CDATA cdata = new CDATA(null);
assertEquals("incorrect CDATA text", "", cdata.getText());
cdata.append((String) null);
assertEquals("incorrect CDATA text", "", cdata.getText());
try {
cdata.append(cdataEndText);
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set it to the null (after it was set to another string so that we
// are sure comething has changed)
final CDATA cdata = new CDATA(null);
assertEquals("incorrect CDATA text", "", cdata.getText());
cdata.append((Text) null);
assertEquals("incorrect CDATA text", "", cdata.getText());
try {
cdata.append(cdataEndText);
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set text with some special characters
final CDATA cdata = new CDATA(specialCharactersText);
assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
cdata.append(specialCharactersText);
assertEquals("incorrect CDATA text", specialCharactersText + specialCharactersText, cdata.getText());
try {
cdata.append(cdataEndText);
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
try {
// set text with some special characters which sould result into an exception
final CDATA cdata = new CDATA(specialText);
assertEquals("incorrect CDATA text", specialText, cdata.getText());
cdata.append(specialText);
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
/**
* Test appending text values to this CDATA.
*/
public void test_TCM___append_Text() {
final String emptyString = "";
final String nullString = null;
final String text = "this is a CDATA section";
final String otherString = "12345qwerty";
final String specialCharactersText = "this is CDATA section with special characters as < > & & < > [[ ]] > <![![";
final String specialText = "> this is a CDATA section with special characters as ]]";
final String cdataEndText = "this is aCDATA section with a CDATA end marke ]]> somewhere inside";
{
// simple text in CDATA section
final CDATA cdata = new CDATA(text);
assertEquals("incorrect CDATA text", text, cdata.getText());
cdata.append(new Text(text));
assertEquals("incorrect CDATA text", text+text, cdata.getText());
try {
cdata.append(new Text(cdataEndText));
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set it to the empty string
final CDATA cdata = new CDATA(emptyString);
assertEquals("incorrect CDATA text", "", cdata.getText());
cdata.append(new Text(emptyString));
assertEquals("incorrect CDATA text", "", cdata.getText());
cdata.append(new Text(text));
assertEquals("incorrect CDATA text", text, cdata.getText());
cdata.append(new Text(nullString));
assertEquals("incorrect CDATA text", text, cdata.getText());
cdata.append(new Text(specialCharactersText));
assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
cdata.append(new Text(nullString));
assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
cdata.append(new Text(emptyString));
assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
cdata.append(new Text(otherString));
assertEquals("incorrect CDATA text", text + specialCharactersText + otherString, cdata.getText());
try {
cdata.append(new Text(cdataEndText));
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set it to a another string
final CDATA cdata = new CDATA(otherString);
assertEquals("incorrect CDATA text", otherString, cdata.getText());
cdata.append(new Text(text));
assertEquals("incorrect CDATA text", otherString + text, cdata.getText());
cdata.append(new Text(nullString));
assertEquals("incorrect CDATA text", otherString + text, cdata.getText());
cdata.append(new Text(specialCharactersText));
assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
cdata.append(new Text(nullString));
assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
cdata.append(new Text(emptyString));
assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
try {
cdata.append(new Text(cdataEndText));
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set it to the null (after it was set to another string so that we
// are sure comething has changed)
final CDATA cdata = new CDATA(nullString);
assertEquals("incorrect CDATA text", "", cdata.getText());
cdata.append(new Text(specialCharactersText));
assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
cdata.append(new Text(nullString));
assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
cdata.append(new Text(text));
assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
cdata.append(new Text(nullString));
assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
cdata.append(new Text(emptyString));
assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
cdata.append(new Text(otherString));
assertEquals("incorrect CDATA text", specialCharactersText + text + otherString, cdata.getText());
try {
cdata.append(new Text(cdataEndText));
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set it to the null (after it was set to another string so that we
// are sure comething has changed)
final CDATA cdata = new CDATA(null);
assertEquals("incorrect CDATA text", "", cdata.getText());
cdata.append((String) null);
assertEquals("incorrect CDATA text", "", cdata.getText());
try {
cdata.append(new Text(cdataEndText));
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set it to the null (after it was set to another string so that we
// are sure comething has changed)
final CDATA cdata = new CDATA(null);
assertEquals("incorrect CDATA text", "", cdata.getText());
cdata.append((Text) null);
assertEquals("incorrect CDATA text", "", cdata.getText());
try {
cdata.append(new Text(cdataEndText));
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
{
// set text with some special characters
final CDATA cdata = new CDATA(specialCharactersText);
assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
cdata.append(new Text(specialCharactersText));
assertEquals("incorrect CDATA text", specialCharactersText + specialCharactersText, cdata.getText());
try {
cdata.append(new Text(cdataEndText));
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
try {
// set text with some special characters which sould result into an exception
final CDATA cdata = new CDATA(specialText);
assertEquals("incorrect CDATA text", specialText, cdata.getText());
cdata.append(new Text(specialText));
fail("failed to detect CDATA end marker");
} catch (final IllegalDataException exception) {
}
}
/**
* Verify that the text of the CDATA matches expected value.
* It assumes that the contrutor is working correctly
*/
public void test_TCM__String_getText() {
{
final String text = "this is a CDATA section";
final CDATA cdata = new CDATA(text);
assertEquals("incorrect CDATA text", text, cdata.getText());
}
{
//set it to the empty string
final String emptyString = "";
final CDATA cdata = new CDATA(emptyString);
assertEquals("incorrect CDATA text", emptyString, cdata.getText());
}
{
// set it to a another string
final String otherString = "12345qwerty";
final CDATA cdata = new CDATA(otherString);
assertEquals("incorrect CDATA text", otherString, cdata.getText());
}
{
// set it to the null
final CDATA cdata = new CDATA(null);
assertEquals("incorrect CDATA text", "", cdata.getText());
}
}
/**
* check for the expected toString text value of Comment.
*/
public void test_TCM__String_toString() {
{
final String text = "this is a simple CDATA section";
final CDATA cdata = new CDATA(text);
assertEquals(
"incorrect CDATA constructed",
"[CDATA: " + text + ']',
cdata.toString());
}
{
final String text = "this is CDATA section with special characters as < > & & < > [[ ]] > <![![";
final CDATA cdata = new CDATA(text);
assertEquals(
"incorrect CDATA constructed",
"[CDATA: " + text + ']',
cdata.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -