Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Rename log assertion classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen O'Rourke and Yong Zhou committed Aug 31, 2018
1 parent cad2b9e commit 877519a
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,238 +23,238 @@ import org.assertj.core.error.ShouldNotContainCharSequence.shouldNotContain
import org.assertj.core.util.Objects.areEqual
import kotlin.reflect.KClass

class Log4jRuleAssert(actual: List<LoggingEvent>) : LogRuleAssert<Log4jRuleAssert, Level, LoggingEvent>(actual) {
class Log4jAssert(actual: List<LoggingEvent>) : LogRuleAssert<Log4jAssert, Level, LoggingEvent>(actual) {

override fun hasInfo(): Log4jRuleAssert =
override fun hasInfo(): Log4jAssert =
hasEvent(Level.INFO)

override fun hasInfo(predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert =
override fun hasInfo(predicate: (LoggingEvent) -> Boolean): Log4jAssert =
hasEvent(Level.INFO, predicate)

override fun hasInfo(message: String): Log4jRuleAssert =
override fun hasInfo(message: String): Log4jAssert =
hasEvent(Level.INFO, message)

override fun hasInfo(message: String, throwable: Throwable): Log4jRuleAssert =
override fun hasInfo(message: String, throwable: Throwable): Log4jAssert =
hasEvent(Level.INFO, message, throwable)

override fun hasInfo(message: String, throwableClass: Class<out Throwable>): Log4jRuleAssert =
override fun hasInfo(message: String, throwableClass: Class<out Throwable>): Log4jAssert =
hasEvent(Level.INFO, message, throwableClass)

override fun hasInfo(message: String, throwableClass: KClass<out Throwable>): Log4jRuleAssert =
override fun hasInfo(message: String, throwableClass: KClass<out Throwable>): Log4jAssert =
hasEvent(Level.INFO, message, throwableClass)

override fun hasInfoContaining(vararg messages: String): Log4jRuleAssert =
override fun hasInfoContaining(vararg messages: String): Log4jAssert =
hasEventContaining(Level.INFO, *messages)

override fun hasInfoMatching(regex: Regex): Log4jRuleAssert =
override fun hasInfoMatching(regex: Regex): Log4jAssert =
hasEventMatching(Level.INFO, regex)

override fun hasInfoMatching(regex: Regex, throwable: Throwable): Log4jRuleAssert =
override fun hasInfoMatching(regex: Regex, throwable: Throwable): Log4jAssert =
hasEventMatching(Level.INFO, regex, throwable)

override fun hasInfoMatching(regex: Regex, throwableClass: Class<out Throwable>): Log4jRuleAssert =
override fun hasInfoMatching(regex: Regex, throwableClass: Class<out Throwable>): Log4jAssert =
hasEventMatching(Level.INFO, regex, throwableClass)

override fun hasInfoMatching(regex: Regex, throwableClass: KClass<out Throwable>): Log4jRuleAssert =
override fun hasInfoMatching(regex: Regex, throwableClass: KClass<out Throwable>): Log4jAssert =
hasEventMatching(Level.INFO, regex, throwableClass)

override fun hasNoInfo(): Log4jRuleAssert =
override fun hasNoInfo(): Log4jAssert =
hasNoEvent(Level.INFO)

override fun hasNoInfo(predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert =
override fun hasNoInfo(predicate: (LoggingEvent) -> Boolean): Log4jAssert =
hasNoEvent(Level.INFO, predicate)

override fun hasNoInfo(message: String): Log4jRuleAssert =
override fun hasNoInfo(message: String): Log4jAssert =
hasNoEvent(Level.INFO, message)

override fun hasNoInfoContaining(vararg messages: String): Log4jRuleAssert =
override fun hasNoInfoContaining(vararg messages: String): Log4jAssert =
hasNoEventContaining(Level.INFO, *messages)

override fun hasNoInfoMatching(regex: Regex): Log4jRuleAssert =
override fun hasNoInfoMatching(regex: Regex): Log4jAssert =
hasNoEventMatching(Level.INFO, regex)

override fun hasWarn(): Log4jRuleAssert =
override fun hasWarn(): Log4jAssert =
hasEvent(Level.WARN)

override fun hasWarn(predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert =
override fun hasWarn(predicate: (LoggingEvent) -> Boolean): Log4jAssert =
hasEvent(Level.WARN, predicate)

override fun hasWarn(message: String): Log4jRuleAssert =
override fun hasWarn(message: String): Log4jAssert =
hasEvent(Level.WARN, message)

override fun hasWarn(message: String, throwable: Throwable): Log4jRuleAssert =
override fun hasWarn(message: String, throwable: Throwable): Log4jAssert =
hasEvent(Level.WARN, message, throwable)

override fun hasWarn(message: String, throwableClass: Class<out Throwable>): Log4jRuleAssert =
override fun hasWarn(message: String, throwableClass: Class<out Throwable>): Log4jAssert =
hasEvent(Level.WARN, message, throwableClass)

override fun hasWarn(message: String, throwableClass: KClass<out Throwable>): Log4jRuleAssert =
override fun hasWarn(message: String, throwableClass: KClass<out Throwable>): Log4jAssert =
hasEvent(Level.WARN, message, throwableClass)

override fun hasWarnContaining(vararg messages: String): Log4jRuleAssert =
override fun hasWarnContaining(vararg messages: String): Log4jAssert =
hasEventContaining(Level.WARN, *messages)

override fun hasWarnMatching(regex: Regex): Log4jRuleAssert =
override fun hasWarnMatching(regex: Regex): Log4jAssert =
hasEventMatching(Level.WARN, regex)

override fun hasWarnMatching(regex: Regex, throwable: Throwable): Log4jRuleAssert =
override fun hasWarnMatching(regex: Regex, throwable: Throwable): Log4jAssert =
hasEventMatching(Level.WARN, regex, throwable)

override fun hasWarnMatching(regex: Regex, throwableClass: Class<out Throwable>): Log4jRuleAssert =
override fun hasWarnMatching(regex: Regex, throwableClass: Class<out Throwable>): Log4jAssert =
hasEventMatching(Level.WARN, regex, throwableClass)

override fun hasWarnMatching(regex: Regex, throwableClass: KClass<out Throwable>): Log4jRuleAssert =
override fun hasWarnMatching(regex: Regex, throwableClass: KClass<out Throwable>): Log4jAssert =
hasEventMatching(Level.WARN, regex, throwableClass)

override fun hasNoWarn(): Log4jRuleAssert =
override fun hasNoWarn(): Log4jAssert =
hasNoEvent(Level.WARN)

override fun hasNoWarn(predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert =
override fun hasNoWarn(predicate: (LoggingEvent) -> Boolean): Log4jAssert =
hasNoEvent(Level.WARN, predicate)

override fun hasNoWarn(message: String): Log4jRuleAssert =
override fun hasNoWarn(message: String): Log4jAssert =
hasNoEvent(Level.WARN, message)

override fun hasNoWarnContaining(vararg messages: String): Log4jRuleAssert =
override fun hasNoWarnContaining(vararg messages: String): Log4jAssert =
hasNoEventContaining(Level.WARN, *messages)

override fun hasNoWarnMatching(regex: Regex): Log4jRuleAssert =
override fun hasNoWarnMatching(regex: Regex): Log4jAssert =
hasNoEventMatching(Level.WARN, regex)

override fun hasError(): Log4jRuleAssert =
override fun hasError(): Log4jAssert =
hasEvent(Level.ERROR)

override fun hasError(predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert =
override fun hasError(predicate: (LoggingEvent) -> Boolean): Log4jAssert =
hasEvent(Level.ERROR, predicate)

override fun hasError(message: String): Log4jRuleAssert =
override fun hasError(message: String): Log4jAssert =
hasEvent(Level.ERROR, message)

override fun hasError(message: String, throwable: Throwable): Log4jRuleAssert =
override fun hasError(message: String, throwable: Throwable): Log4jAssert =
hasEvent(Level.ERROR, message, throwable)

override fun hasError(message: String, throwableClass: Class<out Throwable>): Log4jRuleAssert =
override fun hasError(message: String, throwableClass: Class<out Throwable>): Log4jAssert =
hasEvent(Level.ERROR, message, throwableClass)

override fun hasError(message: String, throwableClass: KClass<out Throwable>): Log4jRuleAssert =
override fun hasError(message: String, throwableClass: KClass<out Throwable>): Log4jAssert =
hasEvent(Level.ERROR, message, throwableClass.java)

override fun hasErrorContaining(vararg messages: String): Log4jRuleAssert =
override fun hasErrorContaining(vararg messages: String): Log4jAssert =
hasEventContaining(Level.ERROR, *messages)

override fun hasErrorMatching(regex: Regex): Log4jRuleAssert =
override fun hasErrorMatching(regex: Regex): Log4jAssert =
hasEventMatching(Level.ERROR, regex)

override fun hasErrorMatching(regex: Regex, throwable: Throwable): Log4jRuleAssert =
override fun hasErrorMatching(regex: Regex, throwable: Throwable): Log4jAssert =
hasEventMatching(Level.ERROR, regex, throwable)

override fun hasErrorMatching(regex: Regex, throwableClass: Class<out Throwable>): Log4jRuleAssert =
override fun hasErrorMatching(regex: Regex, throwableClass: Class<out Throwable>): Log4jAssert =
hasEventMatching(Level.ERROR, regex, throwableClass)

override fun hasErrorMatching(regex: Regex, throwableClass: KClass<out Throwable>): Log4jRuleAssert =
override fun hasErrorMatching(regex: Regex, throwableClass: KClass<out Throwable>): Log4jAssert =
hasEventMatching(Level.ERROR, regex, throwableClass.java)

override fun hasNoError(): Log4jRuleAssert =
override fun hasNoError(): Log4jAssert =
hasNoEvent(Level.ERROR)

override fun hasNoError(predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert =
override fun hasNoError(predicate: (LoggingEvent) -> Boolean): Log4jAssert =
hasNoEvent(Level.ERROR, predicate)

override fun hasNoError(message: String): Log4jRuleAssert =
override fun hasNoError(message: String): Log4jAssert =
hasNoEvent(Level.ERROR, message)

override fun hasNoErrorContaining(vararg messages: String): Log4jRuleAssert =
override fun hasNoErrorContaining(vararg messages: String): Log4jAssert =
hasNoEventContaining(Level.ERROR, *messages)

override fun hasNoErrorMatching(regex: Regex): Log4jRuleAssert =
override fun hasNoErrorMatching(regex: Regex): Log4jAssert =
hasNoEventMatching(Level.ERROR, regex)

override fun hasEvent(level: Level): Log4jRuleAssert =
override fun hasEvent(level: Level): Log4jAssert =
hasEvent("[$level]",
withLevel(level))

override fun hasEvent(level: Level, predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert =
override fun hasEvent(level: Level, predicate: (LoggingEvent) -> Boolean): Log4jAssert =
hasEvent("$level event matching given predicate") {
withLevel(level)(it)
&& predicate(it) }

override fun hasEvent(level: Level, message: String): Log4jRuleAssert =
override fun hasEvent(level: Level, message: String): Log4jAssert =
hasEvent(formatLogMessage(level, message)) {
withLevel(level)(it)
&& withMessage(message)(it) }

override fun hasEvent(level: Level, message: String, throwable: Throwable): Log4jRuleAssert =
override fun hasEvent(level: Level, message: String, throwable: Throwable): Log4jAssert =
hasEvent(formatLogMessage(level, message)) {
withLevel(level)(it)
&& withMessage(message)(it)
&& withThrowable(throwable)(it) }

override fun hasEvent(level: Level, message: String, throwableClass: Class<out Throwable>): Log4jRuleAssert =
override fun hasEvent(level: Level, message: String, throwableClass: Class<out Throwable>): Log4jAssert =
hasEvent(formatLogMessage(level, message)) {
withLevel(level)(it)
&& withMessage(message)(it)
&& withThrowableClass(throwableClass)(it) }

override fun hasEvent(level: Level, message: String, throwableClass: KClass<out Throwable>): Log4jRuleAssert =
override fun hasEvent(level: Level, message: String, throwableClass: KClass<out Throwable>): Log4jAssert =
hasEvent(level, message, throwableClass.java)

override fun hasEventContaining(level: Level, vararg messages: String): Log4jRuleAssert =
override fun hasEventContaining(level: Level, vararg messages: String): Log4jAssert =
hasEvent("$level message containing ${messages.contentToString()}") {
withLevel(level)(it)
&& withMessageContaining(messages)(it) }

override fun hasEventMatching(level: Level, regex: Regex): Log4jRuleAssert =
override fun hasEventMatching(level: Level, regex: Regex): Log4jAssert =
hasEvent("$level message matching: $regex") {
withLevel(level)(it)
&& withMessageMatching(regex)(it) }

override fun hasEventMatching(level: Level, regex: Regex, throwable: Throwable): Log4jRuleAssert =
override fun hasEventMatching(level: Level, regex: Regex, throwable: Throwable): Log4jAssert =
hasEvent("$level message matching: $regex") {
withLevel(level)(it)
&& withMessageMatching(regex)(it)
&& withThrowable(throwable)(it) }

override fun hasEventMatching(level: Level, regex: Regex, throwableClass: Class<out Throwable>): Log4jRuleAssert =
override fun hasEventMatching(level: Level, regex: Regex, throwableClass: Class<out Throwable>): Log4jAssert =
hasEvent("$level message matching: $regex") {
withLevel(level)(it)
&& withMessageMatching(regex)(it)
&& withThrowableClass(throwableClass)(it) }

override fun hasEventMatching(level: Level, regex: Regex, throwableClass: KClass<out Throwable>): Log4jRuleAssert =
override fun hasEventMatching(level: Level, regex: Regex, throwableClass: KClass<out Throwable>): Log4jAssert =
hasEventMatching(level, regex, throwableClass.java)

override fun hasNoEvent(level: Level): Log4jRuleAssert =
override fun hasNoEvent(level: Level): Log4jAssert =
hasNoEvent("[$level]",
withLevel(level))

override fun hasNoEvent(level: Level, predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert =
override fun hasNoEvent(level: Level, predicate: (LoggingEvent) -> Boolean): Log4jAssert =
hasNoEvent("$level event matching given predicate") {
withLevel(level)(it)
&& predicate(it) }

override fun hasNoEvent(level: Level, message: String): Log4jRuleAssert =
override fun hasNoEvent(level: Level, message: String): Log4jAssert =
hasNoEvent(formatLogMessage(level, message)) {
withLevel(level)(it)
&& withMessage(message)(it) }

override fun hasNoEventContaining(level: Level, vararg messages: String): Log4jRuleAssert =
override fun hasNoEventContaining(level: Level, vararg messages: String): Log4jAssert =
hasNoEvent("$level message containing ${messages.contentToString()}") {
withLevel(level)(it)
&& withMessageContaining(messages)(it) }

override fun hasNoEventMatching(level: Level, regex: Regex): Log4jRuleAssert =
override fun hasNoEventMatching(level: Level, regex: Regex): Log4jAssert =
hasNoEvent("$level message matching: $regex") {
withLevel(level)(it)
&& withMessageMatching(regex)(it) }

private fun hasEvent(description: String, predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert {
private fun hasEvent(description: String, predicate: (LoggingEvent) -> Boolean): Log4jAssert {
if (!actual.any(predicate)) {
failWithMessage(shouldContain(formatLogEvents(actual).replace("%", "%%"), description.replace("%", "%%")).create())
}
return this
}

private fun hasNoEvent(description: String, predicate: (LoggingEvent) -> Boolean): Log4jRuleAssert {
private fun hasNoEvent(description: String, predicate: (LoggingEvent) -> Boolean): Log4jAssert {
if (actual.any(predicate)) {
failWithMessage(shouldNotContain(formatLogEvents(actual).replace("%", "%%"), description.replace("%", "%%")).create())
}
Expand Down Expand Up @@ -282,10 +282,10 @@ class Log4jRuleAssert(actual: List<LoggingEvent>) : LogRuleAssert<Log4jRuleAsser
companion object {

@JvmStatic
fun assertThat(events: List<LoggingEvent>): Log4jRuleAssert = Log4jRuleAssert(events).withRepresentation(Log4jRepresentation())
fun assertThat(events: List<LoggingEvent>): Log4jAssert = Log4jAssert(events).withRepresentation(Log4jRepresentation())

@JvmStatic
fun assertThat(rule: Log4jRule): Log4jRuleAssert = assertThat(rule.events)
fun assertThat(rule: Log4jRule): Log4jAssert = assertThat(rule.events)

fun formatLogEvent(event: LoggingEvent) = formatLogMessage(event.getLevel(), event.renderedMessage)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tyro.oss.logtesting.junit4.log4j

import com.tyro.oss.logtesting.junit4.log4j.Log4jRuleAssert.Companion.formatLogEvent
import com.tyro.oss.logtesting.junit4.log4j.Log4jRuleAssert.Companion.formatLogEvents
import com.tyro.oss.logtesting.junit4.log4j.Log4jAssert.Companion.formatLogEvent
import com.tyro.oss.logtesting.junit4.log4j.Log4jAssert.Companion.formatLogEvents
import org.apache.log4j.spi.LoggingEvent
import org.assertj.core.presentation.StandardRepresentation

Expand Down
Loading

0 comments on commit 877519a

Please sign in to comment.