package com.yidianling.tests; import org.junit.Assert; import org.junit.Test; import static org.junit.Assert.*; /** * Example local unit test, which will execute on the development machine (host). * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ public class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { assertEquals(4, 2 + 2); } String[] list1 = {"17826875951", "1782687595", "178268759", "17826875", "1782687", "178268", "17826", "1782", "178", "17", "1", "17826efdg465154", "165e2244", "111e12345", "我的123是121223423", "我的123456789", "符合规范357545655分好尴尬", "符合规范3555分好尴尬", "订单1234", "订单12345", "我的QQ号是3386218996", "178 2687 5951", "1q1q1q11q", "123456789a"}; String[] list2 = {"178****5951", "178****595", "178****59", "17****75", "17****7", "17****", "1****", "1782", "178", "17", "1", "1****efdg46****", "165e2244", "111e1****", "我的123是121****23", "我的123****89", "符合规范357****55分好尴尬", "符合规范3555分好尴尬", "订单1234", "订单1****", "我的QQ号是338****996", "178 2687 5951", "1q1q1q11q", "123****89a"}; /** * 用于测试数字替换*的功能,功能与ios一样 */ @Test public void set() { for (int tt = 0; tt < list1.length; tt++) { String text = list1[tt]; String assertString = list2[tt]; String lastText = ""; int numberIndex = -1; int numberCount = 0; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) >= 48 && text.charAt(i) <= 57) { numberIndex = i; for (int j = i; j < text.length(); j++) { if (text.charAt(j) >= 48 && text.charAt(j) <= 57) { numberCount++; if (j == text.length() - 1) { if (numberCount >= 5) { while (i < numberIndex + numberCount / 3) { lastText += text.charAt(i++); } while (i < numberIndex + numberCount / 3 + 4) { lastText += "*"; i++; } while (i <= j) { lastText += text.charAt(i++); } } else { while (i <= j) { lastText += text.charAt(i++); } } i = j; break; } } else { if (numberCount >= 5) { while (i < numberIndex + numberCount / 3) { lastText += text.charAt(i++); } while (i < numberIndex + numberCount / 3 + 4) { lastText += "*"; i++; } while (i < j) { lastText += text.charAt(i++); } } else { while (i < j) { lastText += text.charAt(i++); } } i = j - 1; numberIndex = -1; numberCount = 0; break; } } } else { lastText += text.charAt(i); } } assertEquals(lastText, assertString); } } }