How to mock method call and return value without running the method?

前端 未结 2 2044
攒了一身酷
攒了一身酷 2021-02-07 04:24

Consider the following method:

public boolean isACertainValue() {
        if(context.getValueA() != null && context.getValueA().toBoolean() == true) {
           


        
2条回答
  •  眼角桃花
    2021-02-07 04:47

    This code is correct:

    Mockito.when(contextMock.getType()).thenReturn(ContextType.certainType);
    

    But you are getting NullPointerException because you didn't define the Mocking value that should be defines, well I'm using Spring, in my context file when I define @Autowired bean I define it this way:

    
        
    
    

提交回复
热议问题