From 57bc4f4925bf3fd62f376ce4022730ff9a7196ea Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Thu, 3 Nov 2016 21:37:38 +0100 Subject: [PATCH] added unit test for ternary operator --- .../docxstamper/TernaryOperatorTest.java | 37 ++++++++++++++++++ .../docxstamper/TernaryOperatorTest.docx | Bin 0 -> 4396 bytes 2 files changed, 37 insertions(+) create mode 100644 src/test/java/org/wickedsource/docxstamper/TernaryOperatorTest.java create mode 100644 src/test/resources/org/wickedsource/docxstamper/TernaryOperatorTest.docx diff --git a/src/test/java/org/wickedsource/docxstamper/TernaryOperatorTest.java b/src/test/java/org/wickedsource/docxstamper/TernaryOperatorTest.java new file mode 100644 index 00000000..760955f2 --- /dev/null +++ b/src/test/java/org/wickedsource/docxstamper/TernaryOperatorTest.java @@ -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()); + } + + +} diff --git a/src/test/resources/org/wickedsource/docxstamper/TernaryOperatorTest.docx b/src/test/resources/org/wickedsource/docxstamper/TernaryOperatorTest.docx new file mode 100644 index 0000000000000000000000000000000000000000..ba65e2b56b40f6bb44496a8421a4d288ebef6b11 GIT binary patch literal 4396 zcmaJ^2UHUYw51wC4NZELULa_F z4MjSNE+FuO`*&sie|VeO4~Wj**cu%HNJ5{U&Ou1q4B`uWJAyv% zu)c+joD}Ni!Ql{eH5B3v9%}=;2EJDm{ILA$r*%$k}r1j;Pb15Tk*p2341 zz3yYyi}2xM^fb$t0t0OT$?7QnrD=F?xxnHp?DvpuaWNa4 zqa>?Q04yJR1plL$k>}&c#o>tAMXDC{F-uc7IuXp|4BuR<_KWnV!#<42V!7k z4=!2S-_k+-HyyrCetuAoJHBT`s3mDrz554> zt^tKJOJpVQ9c^V42id2j^rL+ikevHh6Z}4VDX}eEfQutyLD{2d7UH(MO$E%5cQZ7` z92ze^y|&gsS~Riv9lbh6ZKuna2br^zW@EoY5va9+0(<% z#LnK`=`6`kBVBz0aZu-xaL!zrFu*}Zq`N!NNQWpCIr_vY7cs6|F*xwDStOa!k{0~h zLV;tuGe|ORI!+x> z@{hEuV8mrwjcVQeke5DkmRVw>qO!W|O5`~P_yQA$fU~!yN9ylmk;zwIMQhszn=&Qp zTQ^e*vMUpqKY$WE(?$E-GvRN`L-LMkFD3V|D(r5t8Q2uMkt7`Dh)$_EXPbm@$T(B6NcvrOPLWT(a8uF!LVrY}dwDu{_nT8dcXKIrOshp12!%=d^tU z%0y9kN=|>8cBJ*=CmZrG?dH9nFOs^QYW8Y;Y_jo_JufOz!^$kj;pH^KF0hUX5zZ6C zNqS1F#`dMCiXYu3b7KUnfRBf_O87hKss5(k*DuK3=|^#OKA!cM0n>$Vf1~UBCY9Vo zUQ|wBQe$3KHtxa?3*Zy)u5q~0WK8;|eozr@T`1PH^j%qnfNYeWho)euTj}G$?!v|* zuWjNTZhHC;kj;{duAnW_M|)LK>>ST>tR@VY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