forked from thombergs/docx-stamper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateReplacementTest.java
More file actions
34 lines (24 loc) · 1.08 KB
/
DateReplacementTest.java
File metadata and controls
34 lines (24 loc) · 1.08 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
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.DateContext;
import org.wickedsource.docxstamper.util.ParagraphWrapper;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateReplacementTest extends AbstractDocx4jTest {
@Test
public void test() throws Docx4JException, IOException {
Date now = new Date();
DateContext context = new DateContext();
context.setDate(now);
InputStream template = getClass().getResourceAsStream("DateReplacementTest.docx");
WordprocessingMLPackage document = stampAndLoad(template, context);
ParagraphWrapper p = new ParagraphWrapper(((P) document.getMainDocumentPart().getContent().get(1)));
Assert.assertEquals("Today is: " + new SimpleDateFormat("dd.MM.yyyy").format(now), p.getText());
}
}