Any (MyClass.class) that actually only matches classes of the type of the passed class?

I have the following code:

verify(javaCompiler, times(1)).writeJavaAndCompile(any(ContractCompilationUnit.class), eq(outputDirectory));
verify(javaCompiler, times(1)).writeJavaAndCompile(any(ParamCompilationUnit.class), eq(outputDirectory));       

and my code is as follows:

javaCompiler.writeJavaAndCompile(new ContractCompilationUnit(), outputDirectory);
javaCompiler.writeJavaAndCompile(new ParamCompilationUnit(), outputDirectory);

The code does not work, because apparently the 1st check shows that there javaCompiler.writeJavaAndCompile()were 2 calls. He does not understand that there is only one type type call ContractCompilationUnit.

What is the standard procedure to avoid this behavior (besides the need to write your own interlocutor)?

+5
source share
1 answer

The documentation shows that this is a known behavior:

, . . , anyObject() -

anyObject()

, , . ( ) .

, isA :

verify(javaCompiler).writeJavaAndCompile(isA(ContractCompilationUnit.class),
                                         eq(outputDirectory));
+6

All Articles