-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertEqualByteArray
(byte[] left, byte[] right) Compares two byte arrays for equalitystatic void
assertEqualByteArray
(byte[] left, byte[] right, String failureMessage) static <T> void
assertEquals
(List<T> left, List<T> right) asserts that two lists are equal in value and order.static <T> void
assertEquals
(List<T> left, List<T> right, String failureMessage) asserts that two lists are equal in value and order.static <T> void
assertEquals
(T left, T right) A helper for testing - assert two generics are equal.static void
assertEqualsDisregardOrder
(List<? extends CharSequence> left, List<? extends CharSequence> right) asserts two lists are equal, ignoring the order.static void
assertEqualsDisregardOrder
(List<? extends CharSequence> left, List<? extends CharSequence> right, String failureMessage) static void
assertFalse
(boolean value) static void
assertFalse
(boolean value, String failureMessage) static <T> T
assertThrows
(Class<T> myEx, ThrowingRunnable r) assert that a particular chunk of code throws a particular exception.static <T> T
assertThrows
(Class<T> myEx, String expectedMsg, ThrowingRunnable r) static void
assertTrue
(boolean value) static void
assertTrue
(boolean value, String failureMessage) Assert that something is true, and show a message if it fails.static Context
buildTestingContext
(String loggerName) static Context
buildTestingContext
(String loggerName, Properties properties) This builds a context very similarly toFullSystem.buildContext()
, except that it usesTestLogger
instead ofLogger
static void
shutdownTestingContext
(Context context)
-
Method Details
-
assertThrows
assert that a particular chunk of code throws a particular exception.Example usage:
assertThrows(TemplateRenderException.class, "Missing a value for key {missing_key}", () -> tp.renderTemplate(myMap));
-
assertThrows
-
assertEquals
public static <T> void assertEquals(T left, T right) A helper for testing - assert two generics are equal. If you need to compare two byte arrays, seeassertEqualByteArray(byte[], byte[])
-
assertEqualByteArray
public static void assertEqualByteArray(byte[] left, byte[] right) Compares two byte arrays for equality -
assertEqualByteArray
-
assertEqualsDisregardOrder
public static void assertEqualsDisregardOrder(List<? extends CharSequence> left, List<? extends CharSequence> right) asserts two lists are equal, ignoring the order. For example, (a, b) is equal to (b, a)Note that the lists must be of comparable objects, or else a ClassCastException will be thrown
-
assertEqualsDisregardOrder
public static void assertEqualsDisregardOrder(List<? extends CharSequence> left, List<? extends CharSequence> right, String failureMessage) -
assertEquals
asserts that two lists are equal in value and order.
For example, (a, b) is equal to (a, b) Does not expect null as an input value. Two empty lists are considered equal. -
assertEquals
asserts that two lists are equal in value and order.
For example, (a, b) is equal to (a, b) Does not expect null as an input value. Two empty lists are considered equal.- Parameters:
failureMessage
- a failureMessage that should be shown if this assertion fails
-
assertTrue
public static void assertTrue(boolean value) -
assertTrue
Assert that something is true, and show a message if it fails. This is also handy for including a kind of documentation in your test code. So, please carefully note this example of its use, because there's a certain subtlety at play:assertTrue(foo == true, "foo must be true");
Notice something here: The message is a statement about what *should* be true. Sometimes, I see people who do it wrong here - they add a message like *foo was wrong*, but that's a disconcerting thing to see in a test. Do it like the example above, instead.
One other detail to mention: If this test fails, it doesn't really give you much help about what the value should have been, it merely insists it be true. In some cases, like where you are asserting that a string contains a substring, it is handy to include what you were looking for and what the string was as part of the failure message.
-
assertFalse
public static void assertFalse(boolean value) -
assertFalse
-
buildTestingContext
-
buildTestingContext
This builds a context very similarly toFullSystem.buildContext()
, except that it usesTestLogger
instead ofLogger
- Parameters:
loggerName
- this will assign a human-readable name to the logger's LoggingActionQueue so we can distinguish it when reviewing the threadsproperties
- If you want, you can inject a properties object here, to have greater control over your test. Using a parameter of null here will cause the system to obtain properties from the minum.config file
-
shutdownTestingContext
-