@Test
public void testStringsMethod(){
System.out.println(Strings.emptyToNull(""));
assertThat(Strings.emptyToNull(""),nullValue());
assertThat(Strings.nullToEmpty(null),equalTo(""));
assertThat(Strings.nullToEmpty("a"),equalTo("a"));
assertThat(Strings.commonPrefix("hello","hit"),equalTo("h"));
assertThat(Strings.commonPrefix("hello","xit"),equalTo(""));
assertThat(Strings.commonSuffix("hello","xit"),equalTo(""));
assertThat(Strings.commonSuffix("hellt","xit"),equalTo("t"));
assertThat(Strings.repeat("xiaowang",2),equalTo("xiaowangxiaowang"));
assertThat(Strings.isNullOrEmpty(""),equalTo(true));
assertThat(Strings.isNullOrEmpty(null),equalTo(true));
assertThat(Strings.padStart("abcd",5,'i'),equalTo("iabcd"));
assertThat(Strings.padEnd("abcd",5,'i'),equalTo("abcdi"));
assertThat(Strings.padStart("abcd",4,'i'),equalTo("abcd"));
assertThat(Strings.padStart("abcd",3,'i'),equalTo("abcd"));
}
@Test
public void testCharMatcher(){
assertThat(CharMatcher.javaDigit().matches('5'),equalTo(true));
assertThat(CharMatcher.javaDigit().matches('x'),equalTo(false));
assertThat(CharMatcher.is('A').countIn("abasasasasaAhjhjhjhjhAhkjjkhhkhaA"),equalTo(3));
assertThat(CharMatcher.breakingWhitespace().collapseFrom(" ahaa ",'*'),equalTo("*ahaa*"));
assertThat(CharMatcher.javaDigit().or(CharMatcher.whitespace()).removeFrom("1aab b3cc "),equalTo("aabbcc"));
assertThat(CharMatcher.javaDigit().or(CharMatcher.whitespace()).retainFrom("1aab b3cc "),equalTo("1 3 "));
}
Guava Strings&CharMatcher
最新推荐文章于 2024-09-07 23:11:32 发布