Mockito NullPointerException

后端 未结 1 1979
不思量自难忘°
不思量自难忘° 2021-01-02 07:29

I followed what @hoaz suggested. However, I am getting nullpointer exception

@RunWith(MockitoJUnitRunner.class)
public class GeneralConfigServiceImplTest  {
         


        
相关标签:
1条回答
  • 2021-01-02 08:09

    You haven't mocked the behavior of getId in externalDependencyObject therefore it is returning null and giving you the NPE when toString() is called on that null.

    You need a when(externalDependencyObject.getId()).then...

    0 讨论(0)
提交回复
热议问题