1

I face the following:

Verification in order failure
Wanted but not invoked:
commandExecutor.execute(
    src/test/resources,
    isNull(),
    "pdflatex",
    ["-interaction=nonstopmode", "-synctex=1", "-src-specials", "-recorder", "-shell-escape", "-output-format=pdf", "test.tex"],
    src/test/resources/test.pdf
);
-> at         org.m2latex.core.LatexProcessorTest.verifyRunLatex(LatexProcessorTest.java:700)
Wanted anywhere AFTER following interaction:
commandExecutor.execute(
    src/test/resources,
    null,
    "pdflatex",
    ["-interaction=nonstopmode", "-synctex=1", "-src-specials", "-recorder", "-shell-escape", "-output-format=pdf", "test.tex"],
    src/test/resources/test.pdf
);
-> at    org.m2latex.core.LatexProcessor.runLatex2dev(LatexProcessor.java:1304)

What I do not understand is, that Mockito seems to see something looking for me as really the same as wanted, but seemingly is not. What is the reason???

The code is as follows:

    this.inOrderExec.verify(this.executor, atLeastOnce())
        .execute(eq(WORKING_DIR),
             isNull(),
             eq(this.settings.getLatex2pdfCommand()),
             eq(LatexProcessor.buildLatexArguments
            (this.settings, 
             this.settings.getPdfViaDvi(), 
             this.texFile)),
             eq(this.dviPdfFile));

I verified also: The code works if I write

    verify(this.executor, atLeastOnce())

i.e. without ordering.

I can post more code if necessary, of course.

Update: it seems as if this problem occurs if and only if I cannot remove the , atLeastOnce() argument. Maybe this is a valuable hint for someone out there....

Update: I found out, that in a method either all verify's work with inOrder like that:

this.inOrder.verify(this.fileUtils).matchInFile 

or neither does.

Special case:

    private void verifyConstrLatexMainDesc() {
    // FIXME: doubling from mockConstrLatexMainDesc()
    String[] suffixes = new String[] {
        LatexProcessor.SUFFIX_VOID,
        LatexProcessor.SUFFIX_PDF,
        "."+this.settings.getPdfViaDvi().getLatexLanguage(),
        LatexProcessor.SUFFIX_LOG,
        LatexProcessor.SUFFIX_IDX,
        LatexProcessor.SUFFIX_IND,
        LatexProcessor.SUFFIX_ILG,
        LatexProcessor.SUFFIX_GLS,
        LatexProcessor.SUFFIX_GLO,
        LatexProcessor.SUFFIX_GLG
    };
        for (int idx = 0; idx < suffixes.length; idx++) {
        //this.inOrder.
        //if (idx == 1 ||idx == 2) {continue;}
        verify(this.fileUtils, atLeastOnce())
        .replaceSuffix(this.texFile, suffixes[idx]);
    }
    }

Ok, I see that this works if indices 1 and 2 are left out. Then one can also leave away atLeastOnce() I suspect that the problem is that a new string is created, right? or that in my case, two arguments are '.pdf'

The other methods which work only for atLeastOnce() are so that they are invoked more than once.

Is this a valuable hint?

Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63
user2609605
  • 419
  • 2
  • 14
  • What else are you verifying in order? It seems like the interaction is happening once, and then you are trying to verify it happens again. Also your output looks a bit strange with `isNull()` as the second argument to the "wanted but not invoked" error. – Adam Dec 14 '16 at 16:03
  • Does `buildLatexArguments` return a `String[]` array, or a `List`? Bear in mind that [arrays compare for referential equality](http://stackoverflow.com/q/8777257/1426891), so different instances with equal contents may fail the `eq` match without appearing different in their string representations. Mockito's [`aryEq`](https://static.javadoc.io/org.mockito/mockito-core/2.1.0-RC.1/org/mockito/AdditionalMatchers.html#aryEq(T[])) matcher can compare the contents of arrays. – Jeff Bowman Dec 14 '16 at 18:05
  • @adam: yes, the isNull looks strange, but whatelse can I do apart from isNull()? – user2609605 Dec 15 '16 at 23:56
  • @Jeff: Ah, good point. I fixed that. I Think aryEq is really hidden! – user2609605 Dec 15 '16 at 23:57
  • I updated the original question: made additional observations but still I cannot figure out what happened. – user2609605 Dec 16 '16 at 00:27

0 Answers0