-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit test for ternary operator
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/test/java/org/wickedsource/docxstamper/TernaryOperatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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.replace.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); | ||
resolvedExpressionsAreReplaced(document); | ||
unresolvedExpressionsAreNotReplaced(document); | ||
} | ||
|
||
private void resolvedExpressionsAreReplaced(WordprocessingMLPackage document) { | ||
P nameParagraph = (P) document.getMainDocumentPart().getContent().get(3); | ||
Assert.assertEquals("Homer <-- this should read \"Homer\".", new ParagraphWrapper(nameParagraph).getText()); | ||
} | ||
|
||
private void unresolvedExpressionsAreNotReplaced(WordprocessingMLPackage document) { | ||
P fooParagraph = (P) document.getMainDocumentPart().getContent().get(4); | ||
Assert.assertEquals("<-- this should be empty.", new ParagraphWrapper(fooParagraph).getText().trim()); | ||
} | ||
|
||
|
||
} |
Binary file added
BIN
+4.29 KB
src/test/resources/org/wickedsource/docxstamper/TernaryOperatorTest.docx
Binary file not shown.