1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > android 去空字符串 android – TextUtils.isEmpty()方法为空字符串返回false

android 去空字符串 android – TextUtils.isEmpty()方法为空字符串返回false

时间:2018-11-16 18:09:45

相关推荐

android 去空字符串 android – TextUtils.isEmpty()方法为空字符串返回false

对于空字符串,它应该返回true.

从TextUtils的源代码:

public static boolean isEmpty(@Nullable CharSequence str) {

if (str == null || str.length() == 0)

return true;

else

return false;

}

在测试中尝试使用以下内容:

mockStatic(TextUtils.class);

when(TextUtils.isEmpty(any(CharSequence.class))).thenAnswer(new Answer() {

@Override

public Boolean answer(InvocationOnMock invocation) throws Throwable {

Object[] args = invocation.getArguments();

String string = (String) args[0];

return (string == null || string.length() == 0);

}

});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。