I am using Mocikto framework (version 1.9.5) in my project for unit testing with Java 1.7 now I am migrating my project to build and run with Java 1.8.
In one of my unit test I am trying to mock following method
public <T> List<T> myMethod(final String sql, final MyMapper<T> MyMapper, final Argument... args)
with this code
String learningId = "testLeaId";
String catalogId = "testCatId";
List<String> returnList = new ArrayList<String>();
returnList.add(catalogId);
when(myService.myMethod(Mockito.anyString(), Mockito.any(MyMapper.class), (Argument[]) Mockito.anyVararg())).thenReturn(returnList);
This code works fine with Java 1.7 now when I upgraded my Java version to 1.8 in my pom.xml I am getting following error...
[ERROR] The method myMethod(String, MyMapper<T>, Argument...) in the type MyService is not applicable for the arguments (String, MyMapper, Argument)
C:\somepath\MyDaoTest.java:59
Can any one help me to solve this error ? Thanks
With Java 8, type inference has been improved, thus you should be able to change
Mockito.any(MyMapper.class)
to
Mockity.any()
for example. (assuming you are using a recent version of Mockito itself)
And you can find then ... that anyVarArg()
is deprecated, and to use any()
for that, too!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With