public class VisibleAssertions extends Object
Output is to stdout, and is coloured if the terminal supports it.
| Modifier | Constructor and Description |
|---|---|
protected |
VisibleAssertions() |
| Modifier and Type | Method and Description |
|---|---|
static void |
assertEquals(String message,
Object expected,
Object actual)
Assert that an actual value is equal to an expected value.
|
static void |
assertFalse(String message,
boolean value)
Assert that a value is false.
|
static void |
assertNotEquals(String message,
Object expected,
Object actual)
Assert that an actual value is not equal to an expected value.
|
static void |
assertNotNull(String message,
Object o)
Assert that a value is not null.
|
static void |
assertNull(String message,
Object o)
Assert that a value is null.
|
static void |
assertRoughlyEquals(String message,
Double expected,
Double actual,
Double epsilon)
Assert that an actual value is approximately equal to an expected value - determined by whether the difference
between the two values is less than a provided epsilon value.
|
static void |
assertSame(String message,
Object expected,
Object actual)
Assert that an actual value is the same object as an expected value.
|
static <T> void |
assertThat(String whatTheObjectIs,
T actual,
org.hamcrest.Matcher<? super T> matcher)
Assert using a Hamcrest matcher.
|
static <T> void |
assertThrows(String message,
Class<? extends Exception> exceptionClass,
Callable<T> callable)
Assert that a given callable throws an exception of a particular class.
|
static void |
assertThrows(String message,
Class<? extends Exception> exceptionClass,
Runnable runnable)
Assert that a given runnable throws an exception of a particular class.
|
static void |
assertTrue(String message,
boolean value)
Assert that a value is true.
|
static void |
assertVisiblyEquals(String message,
Object expected,
Object actual)
Assert that an actual value is visibly equal to an expected value, following conversion to a String via toString().
|
static void |
context(CharSequence context)
Log a contextual message, in the style of a 'dividing line' in the test output.
|
static void |
context(CharSequence context,
int indent)
Log a contextual message, in the style of a 'dividing line' in the test output.
|
static void |
fail(String message)
Just fail with an AssertionError, citing a given message.
|
static void |
fail(String message,
String hint) |
static void |
info(String message)
Log an informational message.
|
static void |
pass(String message)
Indicate that something passed.
|
static void |
warn(String message)
Log a warning message.
|
public static void info(String message)
The output will be in white, following an 'i' symbol.
message - message to outputpublic static void warn(String message)
The output will be in yellow, following a '!' symbol.
message - message to outputpublic static void context(CharSequence context)
The output will be in grey, surrounded by a horizontal line the full width of the current terminal (or 80 chars).
context - contextual message to output.public static void context(CharSequence context, int indent)
The output will be in grey, surrounded by a horizontal line the full width of the current terminal (or 80 chars).
context - contextual message to outputindent - number of space characters to indent this line bypublic static void assertTrue(String message, boolean value)
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomevalue - value to testpublic static void assertFalse(String message, boolean value)
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomevalue - value to testpublic static void assertEquals(String message, Object expected, Object actual)
Equality is tested with the standard Object equals() method, unless both values are null.
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomeexpected - the expected valueactual - the actual valuepublic static void assertVisiblyEquals(String message, Object expected, Object actual)
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomeexpected - the expected valueactual - the actual valuepublic static void assertRoughlyEquals(String message, Double expected, Double actual, Double epsilon)
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomeexpected - the expected valueactual - the actual valueepsilon - the allowable absolute difference between expected and actual valuespublic static void assertNotEquals(String message, Object expected, Object actual)
Equality is tested with the standard Object equals() method, unless both values are null.
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomeexpected - the expected valueactual - the actual valuepublic static void assertNull(String message, Object o)
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomeo - value to testpublic static void assertNotNull(String message, Object o)
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomeo - value to testpublic static void assertSame(String message, Object expected, Object actual)
Sameness is tested with the == operator.
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomeexpected - the expected valueactual - the actual valuepublic static void fail(String message)
A red cross will be shown.
message - message to display alongside the red crosspublic static <T> void assertThat(String whatTheObjectIs, T actual, org.hamcrest.Matcher<? super T> matcher)
T - class of the actual valuewhatTheObjectIs - what is the thing being tested, in a logical senseactual - the actual valuematcher - a matcher to check the actual value againstpublic static <T> void assertThrows(String message, Class<? extends Exception> exceptionClass, Callable<T> callable)
The assertion passes if the callable throws exactly the same class of exception (not a subclass).
If the callable doesn't throw an exception at all, or if another class of exception is thrown, the assertion fails.
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
T - return type of the callablemessage - message to display alongside the assertion outcomeexceptionClass - the expected exception classcallable - a Callable to invokepublic static void assertThrows(String message, Class<? extends Exception> exceptionClass, Runnable runnable)
The assertion passes if the runnable throws exactly the same class of exception (not a subclass).
If the runnable doesn't throw an exception at all, or if another class of exception is thrown, the assertion fails.
If the assertion passes, a green tick will be shown. If the assertion fails, a red cross will be shown.
message - message to display alongside the assertion outcomeexceptionClass - the expected exception classrunnable - a Runnable to invokepublic static void pass(String message)
message - message to display alongside a green tickCopyright © 2018. All rights reserved.