XSSFFont font = new XSSFFont();
font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 14);
XSSFRichTextString str;
STXstring t1, t2, t3;
str = new XSSFRichTextString("Incorrect\nLine-Breaking");
str.applyFont(0, 8, font);
t1 = str.getCTRst().getRList().get(0).xgetT();
t2 = str.getCTRst().getRList().get(1).xgetT();
assertEquals("<xml-fragment>Incorrec</xml-fragment>", t1.xmlText());
assertEquals("<xml-fragment>t\nLine-Breaking</xml-fragment>", t2.xmlText());
str = new XSSFRichTextString("Incorrect\nLine-Breaking");
str.applyFont(0, 9, font);
t1 = str.getCTRst().getRList().get(0).xgetT();
t2 = str.getCTRst().getRList().get(1).xgetT();
assertEquals("<xml-fragment>Incorrect</xml-fragment>", t1.xmlText());
assertEquals("<xml-fragment xml:space=\"preserve\">\nLine-Breaking</xml-fragment>", t2.xmlText());
str = new XSSFRichTextString("Incorrect\n Line-Breaking");
str.applyFont(0, 9, font);
t1 = str.getCTRst().getRList().get(0).xgetT();
t2 = str.getCTRst().getRList().get(1).xgetT();
assertEquals("<xml-fragment>Incorrect</xml-fragment>", t1.xmlText());
assertEquals("<xml-fragment xml:space=\"preserve\">\n Line-Breaking</xml-fragment>", t2.xmlText());
str = new XSSFRichTextString("Tab\tseparated\n");
t1 = str.getCTRst().xgetT();
// trailing \n causes must be preserved
assertEquals("<xml-fragment xml:space=\"preserve\">Tab\tseparated\n</xml-fragment>", t1.xmlText());
str.applyFont(0, 3, font);
t1 = str.getCTRst().getRList().get(0).xgetT();
t2 = str.getCTRst().getRList().get(1).xgetT();
assertEquals("<xml-fragment>Tab</xml-fragment>", t1.xmlText());
assertEquals("<xml-fragment xml:space=\"preserve\">\tseparated\n</xml-fragment>", t2.xmlText());
str = new XSSFRichTextString("Tab\tseparated\n");
str.applyFont(0, 4, font);
t1 = str.getCTRst().getRList().get(0).xgetT();
t2 = str.getCTRst().getRList().get(1).xgetT();
// YK: don't know why, but XmlBeans converts leading tab characters to spaces
//assertEquals("<xml-fragment>Tab\t</xml-fragment>", t1.xmlText());
assertEquals("<xml-fragment xml:space=\"preserve\">separated\n</xml-fragment>", t2.xmlText());
str = new XSSFRichTextString("\n\n\nNew Line\n\n");
str.applyFont(0, 3, font);
str.applyFont(11, 13, font);
t1 = str.getCTRst().getRList().get(0).xgetT();
t2 = str.getCTRst().getRList().get(1).xgetT();
t3 = str.getCTRst().getRList().get(2).xgetT();
// YK: don't know why, but XmlBeans converts leading tab characters to spaces
assertEquals("<xml-fragment xml:space=\"preserve\">\n\n\n</xml-fragment>", t1.xmlText());
assertEquals("<xml-fragment>New Line</xml-fragment>", t2.xmlText());
assertEquals("<xml-fragment xml:space=\"preserve\">\n\n</xml-fragment>", t3.xmlText());
}