Need help to write a unit test using Mockito and JUnit4

前端 未结 10 1057
余生分开走
余生分开走 2020-12-15 04:06

Need help to write a unit test for the below code using Mockito and JUnit4,

public class MyFragmentPresenterImpl { 
      public Boolean isValid(String value         


        
10条回答
  •  不思量自难忘°
    2020-12-15 04:49

    As a followup to Johnny's answer, to catch TextUtils.isEmpty(null) calls as well, you could use this piece of code.

    PowerMockito.mockStatic(TextUtils.class);
    PowerMockito.when(TextUtils.isEmpty(any()))
        .thenAnswer((Answer) invocation -> {
            Object s = invocation.getArguments()[0];
            return s == null || s.length() == 0;
        });
    

提交回复
热议问题