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