forked from thombergs/docx-stamper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressionReplacementWithFormattingTest.java
More file actions
38 lines (28 loc) · 1.4 KB
/
ExpressionReplacementWithFormattingTest.java
File metadata and controls
38 lines (28 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package org.wickedsource.docxstamper;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.wml.P;
import org.docx4j.wml.R;
import org.junit.Assert;
import org.junit.Test;
import org.wickedsource.docxstamper.context.NameContext;
import java.io.IOException;
import java.io.InputStream;
public class ExpressionReplacementWithFormattingTest extends AbstractDocx4jTest {
@Test
public void test() throws Docx4JException, IOException {
NameContext context = new NameContext();
context.setName("Homer Simpson");
InputStream template = getClass().getResourceAsStream("ExpressionReplacementWithFormattingTest.docx");
WordprocessingMLPackage document = stampAndLoad(template, context);
assertBoldStyle((R) ((P) document.getMainDocumentPart().getContent().get(2)).getContent().get(1));
assertItalicStyle((R) ((P) document.getMainDocumentPart().getContent().get(3)).getContent().get(1));
assertBoldStyle((R) ((P) document.getMainDocumentPart().getContent().get(5)).getContent().get(1));
}
private void assertBoldStyle(R run) {
Assert.assertTrue("expected Run to be styled bold!", run.getRPr().getB().isVal());
}
private void assertItalicStyle(R run) {
Assert.assertTrue("expected Run to be styled italic!", run.getRPr().getI().isVal());
}
}