Prevent stubbing of equals method

前端 未结 3 1087
無奈伤痛
無奈伤痛 2020-12-11 01:57

I would like to test my class\' equals() method but Mockito seems to be calling the stub version every time. My test is as follows;

PluginResourceAdapter ada         


        
3条回答
  •  长情又很酷
    2020-12-11 02:24

    By default equals() returns true if object have the same address in memory.
    So

    PluginResourceAdapter adapter; PluginResourceAdapter other; adapter = other = mock (PluginResourceAdapter.class);

    returns true to you. If you want false use

    PluginResourceAdapter adapter = mock (PluginResourceAdapter.class); PluginResourceAdapter other = mock (PluginResourceAdapter.class);

提交回复
热议问题