Skip to content

Commit 9a65d34

Browse files
committed
TextUtils: add mock class for TextUtils.isEmpty
1 parent fe56cef commit 9a65d34

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package android.text;
2+
3+
/**
4+
* This Class Mocks TextUtils for the purpose of testing.
5+
* NOTE: This class would not change the function of the TextUtils used in app
6+
* it onlt mocks it for the unit tests
7+
*
8+
*/
9+
public class TextUtils {
10+
// mocks TextUtils.isEmpty
11+
public static boolean isEmpty(CharSequence str) {
12+
return str == null || str.length() == 0;
13+
}
14+
15+
// mocks TextUtils.equals
16+
public static boolean equals(CharSequence a, CharSequence b) {
17+
if (a == b) return true;
18+
int length;
19+
if (a != null && b != null && (length = a.length()) == b.length()) {
20+
if (a instanceof String && b instanceof String) {
21+
return a.equals(b);
22+
} else {
23+
for (int i = 0; i < length; i++) {
24+
if (a.charAt(i) != b.charAt(i)) return false;
25+
}
26+
return true;
27+
}
28+
}
29+
return false;
30+
}
31+
32+
// mocks TextUtils.isDigitsOnly
33+
public static boolean isDigitsOnly(CharSequence str) {
34+
final int len = str.length();
35+
for (int cp, i = 0; i < len; i += Character.charCount(cp)) {
36+
cp = Character.codePointAt(str, i);
37+
if (!Character.isDigit(cp)) {
38+
return false;
39+
}
40+
}
41+
return true;
42+
}
43+
44+
// mocks TextUtils.isNewline
45+
private static boolean isNewline(int codePoint) {
46+
int type = Character.getType(codePoint);
47+
return type == Character.PARAGRAPH_SEPARATOR || type == Character.LINE_SEPARATOR
48+
|| codePoint == 10;
49+
}
50+
}

0 commit comments

Comments
 (0)