@Test public void testAddElementAliasString() { IDocument myDoc = new Document2004(); myDoc.addEle(Heading1.with("heading1").create().getContent()); assertTrue(myDoc.getBody().getContent().contains("<w:body>")); assertTrue(myDoc.getBody().getContent().contains("<w:t>heading1</w:t>")); assertTrue(myDoc.getBody().getContent().contains("</w:body>")); }
@Test public void testH1Style(){ Heading1 h1 = (Heading1) Heading1.with("222222").withStyle().bold().italic().create(); assertEquals(2, TestUtils.regexCount(h1.getContent(), "<*w:rPr>")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:jc w:val=\"left\" />")); //default is left assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:b/>")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:i/>")); }
@Test public void testFluent(){ Heading1 h1 = (Heading1) Heading1.with("h111").withStyle().bold().italic().align(HeadingStyle.Align.CENTER).create(); Heading2 h2 = (Heading2) Heading2.with("h222").withStyle().bold().italic().align(HeadingStyle.Align.CENTER).create(); Heading3 h3 = (Heading3) Heading3.with("h222").withStyle().bold().italic().align(HeadingStyle.Align.CENTER).create(); verifyStyles(h1); verifyStyles(h2); verifyStyles(h3); }
@Test public void testEmpty(){ Heading1 h1 = Heading1.with(""); assertEquals("", h1.getContent()); Heading2 h2 = Heading2.with(""); assertEquals("", h2.getContent()); Heading3 h3 = Heading3.with(""); assertEquals("", h3.getContent()); }
@Test public void testH1(){ Heading1 h1 = Heading1.with("h1"); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:p wsp:rsidR*")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:t>h1</w:t>")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "</w:p>")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:pStyle w:val=\"Heading1\" />")); }
@Test public void testH1fluent(){ Heading1 h1 = Heading1.with("h1").create(); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:p wsp:rsidR*")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:t>h1</w:t>")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "</w:p>")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:pStyle w:val=\"Heading1\" />")); }
myDoc.addEle(Heading1.with("===== Java2word ======").create()); myDoc.addEle(Heading2.with("===== Headings ======").create()); myDoc.addEle(Paragraph .create()); myDoc.addEle(Heading1.with("Heading01 without styling").create()); myDoc.addEle(Heading2.with("Heading02 with style Center").withStyle() .align(Align.CENTER).italic().create());