亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有辦法模擬 getCTTbl().getTblPr().getTblBorders().

有沒有辦法模擬 getCTTbl().getTblPr().getTblBorders().

慕神8447489 2023-06-14 16:16:19
我寫了一個將數據寫入word文檔的類?,F在我必須為我的班級編寫 mockito 測試。我的問題是我不知道如何在模擬表上模擬 getCTTbl().getTblPr().getTblBorders().getBottom().setColor()。這是我嘗試為其編寫測試的方法的一部分。public  void populateDocumentWithProfileSkills(XWPFDocument document, ExportProfileDTO profileData){        XWPFTable antet = document.createTable();        antet.getCTTbl().getTblPr().getTblBorders().getBottom().setColor(COLOR_OF_TABLE_BORDERS);        antet.getCTTbl().getTblPr().getTblBorders().getRight().setColor(COLOR_OF_TABLE_BORDERS);        antet.getCTTbl().getTblPr().getTblBorders().getLeft().setColor(COLOR_OF_TABLE_ANTET_BACKGROUND);        antet.getCTTbl().getTblPr().getTblBorders().getTop().setColor(COLOR_OF_TABLE_ANTET_BACKGROUND);...}到目前為止我所做的是:@Before    public void setup() {        MockitoAnnotations.initMocks(this);        exportProfileDTO = makeExportProfileDto();        mockDocument = mock(XWPFDocument.class);        mockTable = mock(XWPFTable.class);    }    @Test    public void populateDocumentWithProfileSkills(){        when(mockDocument.createTable()).thenReturn(mockTable);proffesionalSumaryService.populateDocumentWithProfileSkills(mockDocument,exportProfileDTO);    }如果我說CTTbl mockCTTbl = mock(CTTbl.class);when(mockTable.getCTTbl()).thenReturn(mockCTTbl);我將不勝感激有關如何執行此操作的任何建議,或者可能是有關如何測試此類的更好方法。
查看完整描述

2 回答

?
寶慕林4294392

TA貢獻2021條經驗 獲得超8個贊

http://poi.apache.org/components/index.html

poi-ooxml 需要 poi-ooxml-schemas。這是 ooxml-schemas jar 的一個小得多的版本(ooxml-schemas-1.4.jar 用于 POI 4.0.0 或更高版本,ooxml-schemas-1.3.jar 用于 POI 3.14 或 POI 3.17,ooxml-schemas-1.1.jar POI 3.7 至 POI 3.13,ooxml-schemas-1.0.jar 用于 POI 3.5 和 3.6)。較大的 ooxml-schemas jar 通常只需要用于開發。同樣,ooxml-security jar 包含所有與加密和簽名相關的類,通常只在開發時需要。其內容的一個子集在 poi-ooxml-schemas 中。這個 JAR 是 ooxml-security-1.1.jar 用于 POI 3.14 及之前的 ooxml-security-1.0.jar。

這基本上是說您需要將匹配的ooxml-schemasjar 添加到您的 pom 才能訪問所有相關類。

你可能想使用不同的范圍,因為它說它只是開發所必需的,但你必須自己驗證。

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>ooxml-schemas</artifactId>
    <version>1.3</version>
</dependency>


查看完整回答
反對 回復 2023-06-14
?
富國滬深

TA貢獻1790條經驗 獲得超9個贊

我假設您必須在設置方法中以下面的方式使用 Mockito.RETURNS_DEEP_STUBS 選項

 mockDocument = mock(XWPFDocument.class);
 mockTable = mock(XWPFTable.class, Mockito.RETURNS_DEEP_STUBS);

因此 Mockito 框架會為每個 get 調用返回一個模擬,get 調用不必是靜態的。


查看完整回答
反對 回復 2023-06-14
  • 2 回答
  • 0 關注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號