Mockito Voulu, mais pas invoqué: en Fait, il y avait zéro interactions avec ce simulacre

Je sais qu'il y a déjà au moins deux mêmes questions posées, mais je n'arrive toujours pas à comprendre pourquoi je suis l'exception.
J'ai besoin de l'unité de tester cette méthode:

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();
}

et vérifier que

canvas.addTemplate(page, posX, posY); 

a été appelé.

Cette méthode est imbriquée dans une autre méthode:

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);
    }

Et enfin mon code de test unitaire:

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)
    );

Je n'ai pas de méthode final, j'utilise moqué pdf writer comme un paramètre. De quoi ai-je besoin d'autre à faire pour que le test passe?

Mise à JOUR
Ci-dessous le message de l'exception:

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.

Mise à JOUR 2
Après le remplacement de la moqué WithDefinitions objet avec le réel exemple j'obtiens le résultat suivant:

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)
Pouvez-vous passé l'exception (avec la pile) vous recevez dans votre post?

OriginalL'auteur Arthur Eirich | 2015-01-22