Package com.github.valfirst.slf4jtest
Class TestLoggerAssert
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<C,TestLogger>
-
- com.github.valfirst.slf4jtest.TestLoggerAssert
-
- All Implemented Interfaces:
org.assertj.core.api.Assert<TestLoggerAssert,TestLogger>,org.assertj.core.api.Descriptable<TestLoggerAssert>,org.assertj.core.api.ExtensionPoints<TestLoggerAssert,TestLogger>
public class TestLoggerAssert extends org.assertj.core.api.AbstractAssert<C,TestLogger>
A set of assertions to validate that logs have been logged to aTestLogger.Should be thread safe, as this uses
testLogger.getLoggingEvents()by default. The assertion mode can be switched to usetestLogger.getAllLoggingEvents()by callinganyThread().
-
-
Field Summary
Fields Modifier and Type Field Description protected Supplier<List<LoggingEvent>>loggingEventsSupplier
-
Constructor Summary
Constructors Modifier Constructor Description protectedTestLoggerAssert(TestLogger testLogger)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TestLoggerAssertanyThread()Changes the assertion mode to verify that log messages have been logged regardless of which thread actually logged the message.protected static LoggingEventevent(Throwable throwable, Level level, String message, Object... arguments)protected static LoggingEventevent(Level level, String message, Object... arguments)protected longgetLogCount(Level level, Predicate<LoggingEvent> predicate)LevelAsserthasLevel(Level level)Convenience method for aLevelAssertfrom a provided test logger.TestLoggerAsserthasLogged(LoggingEvent event)Verify that aLoggingEventhas been logged by the test logger.TestLoggerAsserthasLogged(Throwable throwable, Level level, String message, Object... arguments)Verify that a log message, at a specific level, has been logged by the test logger in the presence of aThrowable.TestLoggerAsserthasLogged(Level level, String message, Object... arguments)Verify that a log message, at a specific level, has been logged by the test logger.TestLoggerAsserthasNotLogged(LoggingEvent event)Verify that aLoggingEventhas not been logged by the test logger.TestLoggerAsserthasNotLogged(Throwable throwable, Level level, String message, Object... arguments)Verify that a log message, at a specific level, has not been logged by the test logger in the presence of aThrowable.TestLoggerAsserthasNotLogged(Level level, String message, Object... arguments)Verify that a log message, at a specific level, has not been logged by the test logger.protected static Predicate<LoggingEvent>logWithMessage(String message, Object... arguments)protected static Predicate<LoggingEvent>logWithMessage(String message, Optional<Throwable> maybeThrowable, Object... arguments)-
Methods inherited from class org.assertj.core.api.AbstractAssert
asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
-
-
-
-
Field Detail
-
loggingEventsSupplier
protected Supplier<List<LoggingEvent>> loggingEventsSupplier
-
-
Constructor Detail
-
TestLoggerAssert
protected TestLoggerAssert(TestLogger testLogger)
-
-
Method Detail
-
anyThread
public TestLoggerAssert anyThread()
Changes the assertion mode to verify that log messages have been logged regardless of which thread actually logged the message.- Returns:
- a
TestLoggerAssertfor chaining
-
hasLogged
public TestLoggerAssert hasLogged(Level level, String message, Object... arguments)
Verify that a log message, at a specific level, has been logged by the test logger.- Parameters:
level- the level of the log message to look formessage- the expected messagearguments- any optional arguments that may be provided to the log message- Returns:
- a
TestLoggerAssertfor chaining
-
hasLogged
public TestLoggerAssert hasLogged(Throwable throwable, Level level, String message, Object... arguments)
Verify that a log message, at a specific level, has been logged by the test logger in the presence of aThrowable.- Parameters:
throwable- the throwable that is attached to the log messagelevel- the level of the log message to look formessage- the expected messagearguments- any optional arguments that may be provided to the log message- Returns:
- a
TestLoggerAssertfor chaining
-
hasLogged
public TestLoggerAssert hasLogged(LoggingEvent event)
Verify that aLoggingEventhas been logged by the test logger.- Parameters:
event- the event to verify presence of- Returns:
- a
TestLoggerAssertfor chaining
-
hasNotLogged
public TestLoggerAssert hasNotLogged(Level level, String message, Object... arguments)
Verify that a log message, at a specific level, has not been logged by the test logger.- Parameters:
level- the level of the log message to look formessage- the expected messagearguments- any optional arguments that may be provided to the log message- Returns:
- a
TestLoggerAssertfor chaining
-
hasNotLogged
public TestLoggerAssert hasNotLogged(Throwable throwable, Level level, String message, Object... arguments)
Verify that a log message, at a specific level, has not been logged by the test logger in the presence of aThrowable.- Parameters:
throwable- the throwable that is attached to the log messagelevel- the level of the log message to look formessage- the expected messagearguments- any optional arguments that may be provided to the log message- Returns:
- a
TestLoggerAssertfor chaining
-
hasNotLogged
public TestLoggerAssert hasNotLogged(LoggingEvent event)
Verify that aLoggingEventhas not been logged by the test logger.- Parameters:
event- the event to verify absence of- Returns:
- a
TestLoggerAssertfor chaining
-
hasLevel
public LevelAssert hasLevel(Level level)
Convenience method for aLevelAssertfrom a provided test logger.- Parameters:
level- theLevelto assert against- Returns:
- the
LevelAssertbound to the givenLevel
-
getLogCount
protected long getLogCount(Level level, Predicate<LoggingEvent> predicate)
-
logWithMessage
protected static Predicate<LoggingEvent> logWithMessage(String message, Object... arguments)
-
logWithMessage
protected static Predicate<LoggingEvent> logWithMessage(String message, Optional<Throwable> maybeThrowable, Object... arguments)
-
event
protected static LoggingEvent event(Level level, String message, Object... arguments)
-
event
protected static LoggingEvent event(Throwable throwable, Level level, String message, Object... arguments)
-
-