I have a puzzling problem when mocking a class with a method that gets a collection as an argument.
public class Foo {
public Foo () { }
public boolean doSomething(List<Bar> bars) {
return true;
}
}
public class Bar {
public Bar() {}
}
When trying to create a mock
Foo foo = mock(Foo.class);
I get:
Mockito can only mock visible & non-final classes.
If you are not sure...
Underlying exception : java.lang.IllegalArgumentException: java.lang.ClassCastExcception@1ba9917e
...
Sorry for the short error description, I had to copy by hand from offline terminal.
When I change the argument of the doSomething() method to just doSomething(Bar bar) it succeeds in creating the mock.
One final weird thing, it doesn't reproduce on other workstations.
dois a keyword in Java (do whileloop). I wouldn't be surprised if naming method with a keyword would cause some weird errors.