적어도 두 가지 동일한 질문이 있지만 이미 예외가 발생하는 이유를 알 수 없습니다. 내가 단위 테스트에이 방법이 필요합니다Mockito - 실제로는이 모의와 아무런 상호 작용이 없었습니다
void setEyelet(final PdfWriter printPdf, final float posX, final float posY) {
InputStream is = WithDefinitions.class.getResourceAsStream(RES_EYELET); //RES_EYELET is a pdf.
PdfContentByte canvas = printPdf.getDirectContent();
PdfReader reader = new PdfReader(is);
PdfImportedPage page = printPdf.getImportedPage(reader, 1);
canvas.addTemplate(page, posX, posY);
reader.close();
}
및
canvas.addTemplate(page, posX, posY);
가 호출되었는지 확인합니다.
void computeEyelets(final PdfWriter printPdf) {
float lineLeft = borderLeft + EYELET_MARGIN;
float lineRight = printPdfWidth - borderRight - EYELET_MARGIN - EYELET_SIZE;
float lineTop = printPdfHeight - borderTop - EYELET_MARGIN - EYELET_SIZE;
float lineBottom = borderBottom + EYELET_MARGIN;
float eyeletDistMinH = 20;
if (eyeletDistMinH != 0 || eyeletDistMinV != 0) {
setEyelet(printPdf, lineLeft, lineBottom);
}
을 그리고 마지막으로 내 단위 테스트 코드 :
이 방법은 다른 방법에 중첩되어
public void computeEyeletsNoMirror() {
PdfWriter pdfWriter = Mockito.mock(PdfWriter.class);
PdfContentByte pdfContentByte = Mockito.mock(PdfContentByte.class);
Mockito.when(pdfWriter.getDirectContent()).thenReturn(pdfContentByte);
WithDefinitions withDefinitions = Mockito.mock(WithDefinitions.class);
float lineLeft = BORDER_LEFT + EYELET_MARGIN;
float lineBottom = BORDER_BOTTOM + EYELET_MARGIN;
withDefinitions.setEyeletDistMinH(20);
withDefinitions.setEyeletDistMinV(20);
withDefinitions.setMirror(false);
withDefinitions.computeEyelets(pdfWriter);
Mockito.verify(pdfContentByte).addTemplate(
Mockito.any(PdfImportedPage.class),
Mockito.eq(lineLeft),
Mockito.eq(lineBottom)
);
나는 내가 매개 변수로 조롱 PDF 작가를 사용하여, 어떤 최종적인 방법이 없습니다. 검사를 통과하기 위해해야 할 일은 무엇입니까? 2 교체 후 조롱 WithDefinitions 나는 다음과 같은 출력을 얻을 실제 인스턴스와 객체
Wanted but not invoked:
pdfContentByte.addTemplate(
<any>,
62.36221,
62.36221
);
-> at ...tools.pdf.superimpose.WithDefinitionsTest.computeEyeletsNoMirror(WithDefinitionsTest.java:336)
Actually, there were zero interactions with this mock.
UPDATE : 다음은 UPDATE
는 예외 메시지입니다
Argument(s) are different! Wanted:
pdfContentByte.addTemplate(
<any>,
62.36221,
62.36221
);
-> at ...tools.pdf.superimpose.WithDefinitionsTest.computeEyeletsNoMirror(WithDefinitionsTest.java:336)
Actual invocation has different arguments:
pdfContentByte.addTemplate(
null,
48.18898,
48.18898
);
-> at ...tools.pdf.superimpose.WithDefinitions.setEyelet(WithDefinitions.java:850)
같은 의해
를 교체? – Stephan