Browse Source

tests: added unit tests for the StringUtils class.

Provides full test coverage of said class.

Signed-off-by: ardevd <edvard.holst@gmail.com>
ardevd 6 năm trước cách đây
mục cha
commit
fa047b751b

+ 27 - 0
src/test/java/com/owncloud/android/utils/StringUtilsTest.java

@@ -0,0 +1,27 @@
+package com.owncloud.android.utils;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class StringUtilsTest {
+
+    @Test
+    public void searchAndColor_assertCorrectSingleSearchMatch() {
+
+        String text = "this is a simple test";
+        String searchText = "simple";
+        int dummyColorInt = 44221;
+        String expectedReturn = String.format("this is a <font color='%d'><b>%s</b></font> test", dummyColorInt, searchText);
+
+        assertEquals("correctly parsed text returned",
+                     expectedReturn, StringUtils.searchAndColor(text, searchText, dummyColorInt));
+    }
+
+    @Test
+    public void searchAndColor_assertTextReturnedIfSearchTextIsEmpty() {
+        String helloWorld = "hello world";
+        assertEquals("text returned when searchText was empty",
+                     helloWorld, StringUtils.searchAndColor(helloWorld, "", 0));
+    }
+}