Mockito when() doesn't differentiate between child classes

浪尽此生 提交于 2019-11-28 14:23:24
Jeff Bowman

Despite what it would mean when read in English, in Mockito 1.x, any(HttpGet.class) matches any value and not just any HttpGet. The parameter is only used to save a cast previous to Java 8.

From the Matchers.any(Class) documentation:

Matches any object, including nulls

This method doesn't do type checks with the given parameter, it is only there to avoid casting in your code. This might however change (type checks could be added) in a future major release.

Use isA(HttpGet.class) and isA(HttpPost.class) instead, and see Brice's comment below about future changes to the any(Class<?> clazz) matcher.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!