*/
public void setVerticalAlignment(String verticalAlignment) {
CTRPr pr = getRunProperties(true);
- CTVerticalAlignRun vertAlign = pr.getVertAlign();
+ CTVerticalAlignRun vertAlign = pr.isSetVertAlign() ? pr.getVertAlign() : pr.addNewVertAlign();
STVerticalAlignRun align = vertAlign.xgetVal();
if (align == null) {
align = STVerticalAlignRun.Factory.newInstance();
*/
public void setEmphasisMark(String markType) {
CTRPr pr = getRunProperties(true);
- CTEm emphasisMark = pr.getEm();
+ CTEm emphasisMark = pr.isSetEm() ? pr.getEm() : pr.addNewEm();
STEm mark = emphasisMark.xgetVal();
if (mark == null) {
mark = STEm.Factory.newInstance();
@Test
public void testSetGetVerticalAlignment() throws IOException {
XWPFDocument document = new XWPFDocument();
- final XWPFRun run = document.createParagraph().createRun();
+ XWPFRun run = document.createParagraph().createRun();
assertEquals(STVerticalAlignRun.BASELINE, run.getVerticalAlignment());
+ // Reset to a fresh run so we test case of run not having vertical alignment at all
+ run = document.createParagraph().createRun();
run.setVerticalAlignment("subscript");
assertEquals(STVerticalAlignRun.SUBSCRIPT, run.getVerticalAlignment());
run.setVerticalAlignment("superscript");
@Test
public void testSetGetEmphasisMark() throws IOException {
XWPFDocument document = new XWPFDocument();
- final XWPFRun run = document.createParagraph().createRun();
+ XWPFRun run = document.createParagraph().createRun();
assertEquals(STEm.NONE, run.getEmphasisMark());
+ // Reset to a fresh run so we test case of run not having property at all
+ run = document.createParagraph().createRun();
run.setEmphasisMark("dot");
assertEquals(STEm.DOT, run.getEmphasisMark());
document.close();
@Test
public void testSetGetUnderlineColor() throws IOException {
XWPFDocument document = new XWPFDocument();
- final XWPFRun run = document.createParagraph().createRun();
+ XWPFRun run = document.createParagraph().createRun();
assertEquals("auto", run.getUnderlineColor());
+ // Reset to a fresh run so we test case of run not having property at all
+ run = document.createParagraph().createRun();
String colorRgb = "C0F1a2";
run.setUnderlineColor(colorRgb);
assertEquals(colorRgb.toUpperCase(LocaleUtil.getUserLocale()), run.getUnderlineColor());
@Test
public void testSetGetUnderlineThemeColor() throws IOException {
XWPFDocument document = new XWPFDocument();
- final XWPFRun run = document.createParagraph().createRun();
+ XWPFRun run = document.createParagraph().createRun();
assertEquals(STThemeColor.NONE, run.getUnderlineThemeColor());
+ // Reset to a fresh run so we test case of run not having property at all
+ run = document.createParagraph().createRun();
String colorName = "accent4";
run.setUnderlineThemeColor(colorName);
assertEquals(STThemeColor.Enum.forString(colorName), run.getUnderlineThemeColor());