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