2

I have this method, "instance" is @Mock

instance.lookup(
    SomeClass.class.getField("field").getAnnotation(MyAnnotation.class),
    Annotation... annotations
)

Signature of that method is exactly this:

Object lookup(MyAnnotation resource, Annotation... annotations);

Now, that Annotation... value is put there on that mock in runtime in the code I test.

I am trying to Mock it so when I do

Mockito.when(instance.lookup....).thenReturn(something);

but lookup method always returns null value and exception it thrown (it basically do not return "something" but null)

I was thinking that I have to mock these varargs as well so I modified it to this

Mockito.when(instance.lookup(_instance line_, Mockito.any(Annotation[].class)))

but it fails telling me that I am using it "raw".

When I use anyVarargs() like this

Mockito.when(instance.lookup(_that line_, Mockito.anyVararg()))

Mockito.anyVararg() returns Object but I need Annotation[]

Any hint here?

Thanks a lot!

stewenson
  • 1,282
  • 3
  • 15
  • 34
  • 1
    I think you need `Mockito.anyVararg()` as explained here: http://stackoverflow.com/a/2634588/1095318 – Michael Koch Feb 26 '15 at 13:21
  • it still says I am using it raw. I can not use your example in Mockito.when(instance.lookup, Mockito.anyVararg()) – stewenson Feb 26 '15 at 13:30
  • I have to match the first argument as well ... hmmm. I do not have any idea how to match it really. – stewenson Feb 26 '15 at 13:33
  • " can not use your example in Mockito.when(instance.lookup, Mockito.anyVararg())" Why ? What is the error ? – gontard Feb 26 '15 at 14:52

0 Answers0