Skip to content

Commit

Permalink
Fix Comments from MR
Browse files Browse the repository at this point in the history
  • Loading branch information
amp authored and AntonOellerer committed Jan 18, 2023
1 parent 07937c0 commit a8e0382
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/docutools/poipath/xwpf/XWPFBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ public XWPFBuilder<XWPFParagraph> paragraph() {
*/
public XWPFBuilder<T> paragraph(String text) {
var paragraphTexts = text.split("\n");
XWPFParagraph paragraph;
if (bodyElement instanceof XWPFDocument document) {
Arrays.stream(paragraphTexts).forEach(t -> document.createParagraph().createRun().setText(t));
paragraph = document.createParagraph();
} else if (bodyElement instanceof XWPFTableCell cell) {
Arrays.stream(paragraphTexts).forEach(t -> cell.addParagraph().createRun().setText(t));
paragraph = cell.addParagraph();
} else {
throw isUnsupported(XWPFParagraph.class);
}
paragraph.createRun().setText(text);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.docutools.poipath.xwpf.XWPFBuilder.buildDocument;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -78,7 +79,7 @@ void addMultipleParagraphs() {

// Assert
assertThat(Objects.requireNonNull(wrap(document).bodyElement(0).asParagraph()).text(), startsWith("Lorem ipsum"));
assertThat(Objects.requireNonNull(wrap(document).bodyElement(1).asParagraph()).text(), startsWith("Tellus id"));
assertThat(Objects.requireNonNull(wrap(document).bodyElement(0).asParagraph()).text(), endsWith("arcu."));
}

@Test
Expand Down

0 comments on commit a8e0382

Please sign in to comment.