|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.omnaest.utils.assertion.AssertLogger
public class AssertLogger
An AssertLogger provides methods of a Logger as well as methods of an Assert helper. This allows to
easily log assertion based Exceptions and their stack trace information without having them to be raised into the
callers logic. The callers logic will only have to deal with an easy boolean return value.
AssertLogger assertLogger = new AssertLogger( SampleClass.class );Simple logging:
this.assertLogger.info.message( "Simple message logged with the INFO log level" );
//generate and log a message only if the loglevel of DEBUG is enabled
this.assertLogger.debug.message( new MessageFactory()
{
@Override
public String message()
{
return "Message which is costly to generate";
}
} );
Logging catched exceptions:
try
{
throw new Exception( "Some exception" );
}
catch ( Exception e )
{
this.assertLogger.warn.message( e );
}
Assertions:
assertLogger.debug.assertThat().isTrue( expression ); assertLogger.warn.assertThat().isNotNull( object, "Additional message" ); assertLogger.info.assertThat().fails( "Additional message" );Assertions in combination with control flow:
final Collection<String> collection = ...
if ( this.assertLogger.error.assertThat().isNotEmpty( collection, "This collection must not be empty!" ) )
{
// this block is only executed if the collection is not empty
}
which replaces code like:
try
{
//
Assert.isNotEmpty( collection );
//...
}
catch ( Exception e )
{
this.logger.error( "Assertion failed", e );
}
AssertLogger.Loglevel,
AssertLogger.LoglevelAssert,
Assert,
Logger,
Serialized Form| Nested Class Summary | |
|---|---|
static interface |
AssertLogger.DirectAssert
Provides assert methods |
static interface |
AssertLogger.DirectAssertHandler
Handler of an assertion result which allows to throw Exceptions or log messages |
static interface |
AssertLogger.DirectAssertHandlerMessageChoice
|
static interface |
AssertLogger.DirectAssertResultValueProvider
Allows to resolve the result of any previous assertion |
static interface |
AssertLogger.DirectAssertSuccessFailureChoice
Choice between AssertLogger.DirectAssertSuccessFailureChoice.onSuccess() or AssertLogger.DirectAssertSuccessFailureChoice.onFailure(). |
static interface |
AssertLogger.DirectAssertWithExpression
AssertLogger.DirectAssert with a previous set expression |
static interface |
AssertLogger.Loglevel
Representation of a selected AssertLogger.Loglevel of the AssertLogger. |
static interface |
AssertLogger.LoglevelAssert
Provider for Assert based methods which throws appropriate Exceptions which it catches immediately and logs
it to the underlying Logger using the selected AssertLogger.Loglevel. |
protected static class |
AssertLogger.LoglevelImpl
Implementation for AssertLogger.Loglevel and AssertLogger.LoglevelAssert |
static interface |
AssertLogger.MessageFactory
A AssertLogger.MessageFactory allows to produce messages |
| Field Summary | |
|---|---|
AssertLogger.Loglevel |
debug
|
AssertLogger.Loglevel |
error
|
AssertLogger.Loglevel |
info
|
org.slf4j.Logger |
logger
|
AssertLogger.Loglevel |
trace
|
AssertLogger.Loglevel |
warn
|
| Constructor Summary | |
|---|---|
AssertLogger(Class<?> type)
Creates an AssertLogger using the LoggerFactory to create an Logger instance. |
|
AssertLogger(org.slf4j.Logger logger)
|
|
| Method Summary | |
|---|---|
AssertLogger.DirectAssert |
assertThat()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public final org.slf4j.Logger logger
public final AssertLogger.Loglevel trace
public final AssertLogger.Loglevel debug
public final AssertLogger.Loglevel info
public final AssertLogger.Loglevel warn
public final AssertLogger.Loglevel error
| Constructor Detail |
|---|
public AssertLogger(Class<?> type)
AssertLogger using the LoggerFactory to create an Logger instance.
type - AssertLoggerpublic AssertLogger(org.slf4j.Logger logger)
logger - AssertLogger| Method Detail |
|---|
public AssertLogger.DirectAssert assertThat()
AssertLogger.DirectAssert instance
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||