Is Empty @Test
public void string_is_empty () {
String favoriteCereal = "" ;
assertThat ( favoriteCereal , isEmptyOrNullString ());
}
Is empty or null string @Test
public void string_is_empty_or_null () {
String favoriteCereal = null ;
assertThat ( favoriteCereal , isEmptyOrNullString ());
}
Equal to @Test
public void string_equal_to () {
String favoriteCereal = "cinnamon life" ;
assertThat ( favoriteCereal , equalTo ( "cinnamon life" ));
}
Equal to ignore case @Test
public void string_equal_to_ignoring_case () {
String favoriteCereal = "CINNAMON LIFE" ;
assertThat ( favoriteCereal , equalToIgnoringCase ( "cinnamon life" ));
}
Equal to ignore whitespace @Test
public void string_equal_to_ignoring_whitespace () {
String favoriteCereal = "CINNAMON LIFE " ;
assertThat ( favoriteCereal , equalToIgnoringWhiteSpace ( "cinnamon life" ));
}
Contains string @Test
public void string_contains () {
String cereal = "mini wheats" ;
assertThat ( cereal , containsString ( "mini" ));
}
Ends with @Test
public void string_ends_with () {
String cereal = "corn flakes" ;
assertThat ( cereal , endsWith ( "s" ));
}
Starts with @Test
public void string_starts_with () {
String cereal = "honey smacks" ;
assertThat ( cereal , startsWith ( "honey" ));
}
String contains in order @Test
public void string_has_order () {
String cereal = "apple jacks" ;
assertThat ( cereal , stringContainsInOrder ( Lists . newArrayList ( "apple" , "jacks" )));
}
Hamcrest text matchers posted by Justin Musgrove on 15 August 2013
Tagged: java and java-hamcrest
Share on: Facebook Google+
All the code on this page is available on github:
TextMatchers.java