public class AssertBuilder
extends java.lang.Object
Class provides ability to construct (or throw) an assert error with multiple assert results. "Hamcrest Matchers" are used as main assertion tool.
It is also possible to create instance of the AssertError without throwing it, see build()
method. Or to receive list of collected asserts with getAssertResults() method.
Matcher,
Matchers,
checkThat(Object, Matcher),
checkThat(Object, Matcher, String),
checkThat(Object, Matcher, String, Throwable)| Constructor and Description |
|---|
AssertBuilder() |
| Modifier and Type | Method and Description |
|---|---|
AssertBuilder |
addMessage(java.lang.String message,
java.lang.Object... args)
String.format(String, Object...) is called for the specified message and arguments. |
AssertBuilder |
addResult(AssertResult result) |
java.util.Optional<AssertError> |
build()
If this builder contains any assert results (see
getAssertResults()) then an Optional
containing new instance of an AssertError will be returned. |
<T> AssertBuilder |
checkThat(T item,
org.hamcrest.Matcher<T> matcher)
Performs assertion check of the specified item using hamcrest
Matcher object. |
<T> AssertBuilder |
checkThat(T item,
org.hamcrest.Matcher<T> matcher,
java.lang.String message)
Performs assertion check of the specified item using hamcrest
Matcher object. |
<T> AssertBuilder |
checkThat(T item,
org.hamcrest.Matcher<T> matcher,
java.lang.String message,
java.lang.Throwable cause)
Performs assertion check of the specified item using hamcrest
Matcher object. |
java.util.List<AssertResult> |
getAssertResults()
The same instance of the list is used throughout the building process.
|
void |
performAssert()
Method
build() is called. |
public final java.util.List<AssertResult> getAssertResults()
public java.util.Optional<AssertError> build()
getAssertResults()) then an Optional
containing new instance of an AssertError will be returned. Otherwise an empty optional is returned.public void performAssert()
throws AssertError
build() is called. If it returns instance of the AssertError - it got thrown.AssertErrorpublic AssertBuilder addResult(AssertResult result)
public AssertBuilder addMessage(java.lang.String message, java.lang.Object... args)
String.format(String, Object...) is called for the specified message and arguments.
AssertResult is created with the result message and added to the builder.public <T> AssertBuilder checkThat(T item, org.hamcrest.Matcher<T> matcher)
Performs assertion check of the specified item using hamcrest Matcher object.
If matcher doesn't matches specified item - assert result is created and added to the builder.
public <T> AssertBuilder checkThat(T item, org.hamcrest.Matcher<T> matcher, java.lang.String message)
Performs assertion check of the specified item using hamcrest Matcher object.
If matcher doesn't matches specified item - assert result is created with the specified message
and added to the builder.
public <T> AssertBuilder checkThat(T item, org.hamcrest.Matcher<T> matcher, java.lang.String message, java.lang.Throwable cause)
Performs assertion check of the specified item using hamcrest Matcher object.
If matcher doesn't matches specified item - assert result is created with the specified message,
and specified cause and added to the builder.