forked from thombergs/docx-stamper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTernaryOperatorTest.java
More file actions
45 lines (36 loc) · 2.05 KB
/
TernaryOperatorTest.java
File metadata and controls
45 lines (36 loc) · 2.05 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
39
40
41
42
43
44
45
package org.wickedsource.docxstamper;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.wml.P;
import org.junit.Assert;
import org.junit.Test;
import org.wickedsource.docxstamper.context.NameContext;
import org.wickedsource.docxstamper.util.ParagraphWrapper;
import java.io.IOException;
import java.io.InputStream;
public class TernaryOperatorTest extends AbstractDocx4jTest {
@Test
public void test() throws Docx4JException, IOException {
NameContext context = new NameContext();
context.setName("Homer");
InputStream template = getClass().getResourceAsStream("TernaryOperatorTest.docx");
WordprocessingMLPackage document = stampAndLoad(template, context);
P nameParagraph = (P) document.getMainDocumentPart().getContent().get(3);
Assert.assertEquals("Homer <-- this should read \"Homer\".", new ParagraphWrapper(nameParagraph).getText());
P fooParagraph = (P) document.getMainDocumentPart().getContent().get(4);
Assert.assertEquals("<-- this should be empty.", new ParagraphWrapper(fooParagraph).getText().trim());
}
@Test
public void test2() throws IOException, Docx4JException {
NameContext context = new NameContext();
context.setName("Homer");
InputStream template = getClass().getResourceAsStream("TernaryOperatorTest2.docx");
WordprocessingMLPackage document = stampAndLoad(template, context);
P firstParagraph = (P) document.getMainDocumentPart().getContent().get(1);
Assert.assertEquals("Text before replacement ", new ParagraphWrapper(firstParagraph).getText());
P secondParagraph = (P) document.getMainDocumentPart().getContent().get(2);
Assert.assertEquals("replacement Text after", new ParagraphWrapper(secondParagraph).getText());
P thirdParagraph = (P) document.getMainDocumentPart().getContent().get(3);
Assert.assertEquals("Text before replacement Text after", new ParagraphWrapper(thirdParagraph).getText());
}
}