public class StringAsserts extends Object
If using JDK 1.5 or above, you can static import everything in this class, so that the calls look exactly like built-in JUnit assertions.
Constructor and Description |
---|
StringAsserts() |
Modifier and Type | Method and Description |
---|---|
static void |
assertContainsRegex(String regex,
String str)
Asserts that the passed string contains a specified regular expression,
showing expected/actual on failure.
|
static void |
assertContainsRegex(String message,
String regex,
String str)
Asserts that the passed string contains a specified regular expression,
showing caller-defined failure message on failure.
|
static String |
assertContainsThenRemove(String src,
String expected)
Asserts that a string is contained within another, and then removes
it.
|
static void |
assertDoesntContainRegex(String regex,
String str)
Asserts that the passed string does not contain a specified regular
expression, showing expected/actual on failure.
|
static void |
assertDoesntContainRegex(String message,
String regex,
String str)
Asserts that the passed string does not contain a specified regular
expresion, showing caller-defined failure message on failure.
|
static void |
assertNotEmpty(String value)
Asserts that the passed string is not empty or null.
|
static void |
assertNotEmpty(String message,
String value)
Asserts that the passed string is not empty or null.
|
static void |
assertRegex(String regex,
String actual)
Asserts that the passed string exactly matches a regular expression,
showing expected/actual on failure.
|
static void |
assertRegex(String message,
String regex,
String actual)
Asserts that the passed string exactly matches a regular expression,
showing caller-defined failure message on failure.
|
static void |
assertSubstringCount(String str,
String sub,
int expected)
Asserts that a given string contains N instances of a substring.
|
static void |
assertSubstringCount(String message,
String str,
String sub,
int expected)
Asserts that a given string contains N instances of a substring, and
outputs a specified message if the assertion fails.
|
public static void assertNotEmpty(String value)
public static void assertNotEmpty(String message, String value)
public static void assertSubstringCount(String str, String sub, int expected)
str
- The source string.sub
- The substring to search for.expected
- The number of times that the substring should appear
in the source string.public static void assertSubstringCount(String message, String str, String sub, int expected)
message
- The message to output if assertion fails -- note
that the "expected versus actual" message will be
appended to this.str
- The source string.sub
- The substring to search for.expected
- The number of times that the substring should appear
in the source string.public static void assertRegex(String regex, String actual)
public static void assertRegex(String message, String regex, String actual)
public static void assertContainsRegex(String regex, String str)
public static void assertContainsRegex(String message, String regex, String str)
public static void assertDoesntContainRegex(String regex, String str)
public static void assertDoesntContainRegex(String message, String regex, String str)
public static String assertContainsThenRemove(String src, String expected)
src
- The source string.expected
- The text expected in that string.