如何使用ApachePOIJava为将数据写入word文档的类编写单元测试?

如何使用ApachePOIJava为将数据写入word文档的类编写单元测试?,java,unit-testing,ms-word,mockito,apache-poi,Java,Unit Testing,Ms Word,Mockito,Apache Poi,我用ApachePOI(POIooXML版本3.15)创建了一个word文档,现在我想为我的类编写单元测试。最好的方法是什么?我们在项目中使用mockito(2.15.0) 这是我试图为其编写测试的类之一: @组件 公共类ProffeisonalSumaryService{ public void使用profileskills填充文档(XWPFDocument文档,导出profiled到profileData){ XWPFTable antet=document.createTable(); a

我用ApachePOI(POIooXML版本3.15)创建了一个word文档,现在我想为我的类编写单元测试。最好的方法是什么?我们在项目中使用mockito(2.15.0)

这是我试图为其编写测试的类之一:

@组件
公共类ProffeisonalSumaryService{
public void使用profileskills填充文档(XWPFDocument文档,导出profiled到profileData){
XWPFTable antet=document.createTable();
antet.getCTTbl().getTblPr().getTblBorders().getBottom().setColor(表格边框的颜色);
antet.getCTTbl().getTblPr().getTblBorders().getRight().setColor(表格边框的颜色);
antet.getCTTbl().getTblPr().getTblBorders().getLeft().setColor(表格的颜色\u antet\u背景);
antet.getCTTbl().getTblPr().getTblBorders().getTop().setColor(表格的颜色\u antet\u背景);
CTTblWidth CTTblWidth=antet.getCTTbl().getTblPr().getTblW();
ctTblWidth.setType(STTblWidth.PCT);
ctTblWidth.setW(BigInteger.valueOf(每英寸6*TWIPS_));
XWPFTableRow antetRow=antet.getRow(0);
获取单元格(0)。删除段落(0);
XWPFParagraph professionalSkills=antetRow.getCell(0.addParagraph();
设置样式(professionalSkills.createRun()、字体大小、副标题字体大小、颜色FORTECH、“专业摘要”、真、假);
antetRow.getCell(0.setColor)(表的颜色\u ANTET\u背景);
XWPFParagraph paragraphSkills=document.createparagraphy();
XWPFTable skillsTable=document.createTable();
skillsTable.getCTTbl().getTblPr().getTblBorders().getBottom().setColor(表格边框的颜色);
skillsTable.getCTTbl().getTblPr().getTblBorders().getTop().setColor(表格边框的颜色);
skillsTable.getCTTbl().getTblPr().getTblBorders().getLeft().setColor(表格边框的颜色);
skillsTable.getCTTbl();
skillsTable.getCTTbl();
skillsTable.getCTTbl();
XWPFTableRow projectSkillsRow=skillsTable.getRow(0);
XWPFParagraph_skills=projectSkillsRow.getCell(0.addParagraph();
setStyles(_skills.createRun()、字体校准、字体大小正常、颜色FORTECH、“skills”、false、false);
projectSkillsRow.createCell();
试一试{
setSkillsBulletList(profileData.getSkillList(),文档,projectSkillsRow);
}捕获(XMLE异常){
抛出新的RestExceptions.HeaderError();
}
}
受保护的void setSkillsBulletList(列出技能、XWPFDocument文档、XWPFTableRow projectSkillsRow)引发XmlException{
字符串cTAbstractNumBulletXML=
""
+ ""
+ ""
+ ""
+ ""
+ "";
XWPFRun;
CTNumbering-CTNumbering=CTNumbering.Factory.parse(cTAbstractNumBulletXML);
CTAbstractNum CTAbstractNum=cTNumbering.getAbstractNumArray(0);
XWPFAbstractNum abstractNum=新的XWPFAbstractNum(cTAbstractNum);
XWPFNumber编号=document.createNumber();
BigInteger abstractNumID=number.addAbstractNum(abstractNum);
biginger numID=numbering.addNum(abstractNumID);
获取单元格(1)。删除段落(0);
如果(skillenties.size()!=0)
用于(技能技能:技能){
XWPFParagraph item=projectSkillsRow.getCell(1.addParagraph();
项目.setNumID(numID);
run=item.createRun();
run.setText(skill.getSkillDescriptionEntity().getName()+“-”+skill_SCORES.values()[skill.getskillscores()]);
}
否则{
XWPFParagraph item=projectSkillsRow.getCell(1.addParagraph();
run=item.createRun();
run.setText(“无技能”);
}
}
私有静态void setStyles(XWPFRun运行、字符串fontFamily、int fontSize、字符串colorRGB、字符串文本、布尔粗体、布尔addBreak){
run.setFontFamily(fontFamily);
run.setFontSize(fontSize);
run.setColor(colorRGB);
run.setText(text);
run.setBold(粗体);
如果(addBreak)运行.addBreak();
}
}
这就是我迄今为止所发现和尝试的:


@RunWith(MockitoJUnitRunner.class)
公共类ProffeAlsumaryServiceTest{
私有静态最终字符串UID=“UID”;
私人静态最终智力技能得分=3;
@注射模拟
ProffeonalSumaryService ProffeonalSumaryService;
ExportProfileDTO ExportProfileDTO;
XWPF文件模拟文件;
XWPFTable模拟台;
XWPFTableRow模拟行;
xwfp段落;
XWPFTableCell模拟细胞;
XWPFRun模拟运行;
@以前
公共作废设置(){
initMocks(this);
exportProfileDTO=makeExportProfileDto();
mockDocument=mock(XWPFDocument.class);
mockTable=mock(XWPFTable.class,Mockito.RETURNS\u DEEP\u STUBS);
mockRow=mock(XWPFTableRow.class);
mockParagraph=mock(XWPFParagraph.class);
mockCell=mock(XWPFTableCell.class);
mockRun=mock(XWPFRun.class);
}
@试验
public void使用ProfileSkills()填充文档{
CTBorder mockCTBorder=mock(CTBorder.class);
CTTblWidth mockCTTblWidth=mock(CTTblWidth.class);
当(mockDocument.createTable())。然后返回(mockTable);
当(mockTable.getCTTbl().getTblPr().gettbborders().getBottom())。然后返回(mockCTBorder);
当(mockTable.getCTTbl().getTblPr().getTblBorders().getTop())。然后返回(mockCTBorder);
当(mockTable.getCTTbl().getTblPr().getTb