From 877519a2f71b5cfb0edf6759b0f67c98511c205b Mon Sep 17 00:00:00 2001 From: Stephen O'Rourke and Yong Zhou Date: Fri, 31 Aug 2018 11:57:39 +1000 Subject: [PATCH] Rename log assertion classes --- .../{Log4jRuleAssert.kt => Log4jAssert.kt} | 138 +++++++++--------- .../junit4/log4j/Log4jRepresentation.kt | 4 +- ...{LogbackRuleAssert.kt => LogbackAssert.kt} | 138 +++++++++--------- .../junit4/logback/LogbackRepresentation.kt | 4 +- .../logtesting/junit4/log4j/Log4jRuleTest.kt | 2 +- .../junit4/logback/LogbackRuleTest.kt | 2 +- 6 files changed, 144 insertions(+), 144 deletions(-) rename src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/{Log4jRuleAssert.kt => Log4jAssert.kt} (78%) rename src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/{LogbackRuleAssert.kt => LogbackAssert.kt} (77%) diff --git a/src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRuleAssert.kt b/src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jAssert.kt similarity index 78% rename from src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRuleAssert.kt rename to src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jAssert.kt index a59cca8..2948a83 100644 --- a/src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRuleAssert.kt +++ b/src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jAssert.kt @@ -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) : LogRuleAssert(actual) { +class Log4jAssert(actual: List) : LogRuleAssert(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): Log4jRuleAssert = + override fun hasInfo(message: String, throwableClass: Class): Log4jAssert = hasEvent(Level.INFO, message, throwableClass) - override fun hasInfo(message: String, throwableClass: KClass): Log4jRuleAssert = + override fun hasInfo(message: String, throwableClass: KClass): 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): Log4jRuleAssert = + override fun hasInfoMatching(regex: Regex, throwableClass: Class): Log4jAssert = hasEventMatching(Level.INFO, regex, throwableClass) - override fun hasInfoMatching(regex: Regex, throwableClass: KClass): Log4jRuleAssert = + override fun hasInfoMatching(regex: Regex, throwableClass: KClass): 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): Log4jRuleAssert = + override fun hasWarn(message: String, throwableClass: Class): Log4jAssert = hasEvent(Level.WARN, message, throwableClass) - override fun hasWarn(message: String, throwableClass: KClass): Log4jRuleAssert = + override fun hasWarn(message: String, throwableClass: KClass): 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): Log4jRuleAssert = + override fun hasWarnMatching(regex: Regex, throwableClass: Class): Log4jAssert = hasEventMatching(Level.WARN, regex, throwableClass) - override fun hasWarnMatching(regex: Regex, throwableClass: KClass): Log4jRuleAssert = + override fun hasWarnMatching(regex: Regex, throwableClass: KClass): 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): Log4jRuleAssert = + override fun hasError(message: String, throwableClass: Class): Log4jAssert = hasEvent(Level.ERROR, message, throwableClass) - override fun hasError(message: String, throwableClass: KClass): Log4jRuleAssert = + override fun hasError(message: String, throwableClass: KClass): 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): Log4jRuleAssert = + override fun hasErrorMatching(regex: Regex, throwableClass: Class): Log4jAssert = hasEventMatching(Level.ERROR, regex, throwableClass) - override fun hasErrorMatching(regex: Regex, throwableClass: KClass): Log4jRuleAssert = + override fun hasErrorMatching(regex: Regex, throwableClass: KClass): 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): Log4jRuleAssert = + override fun hasEvent(level: Level, message: String, throwableClass: Class): Log4jAssert = hasEvent(formatLogMessage(level, message)) { withLevel(level)(it) && withMessage(message)(it) && withThrowableClass(throwableClass)(it) } - override fun hasEvent(level: Level, message: String, throwableClass: KClass): Log4jRuleAssert = + override fun hasEvent(level: Level, message: String, throwableClass: KClass): 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): Log4jRuleAssert = + override fun hasEventMatching(level: Level, regex: Regex, throwableClass: Class): Log4jAssert = hasEvent("$level message matching: $regex") { withLevel(level)(it) && withMessageMatching(regex)(it) && withThrowableClass(throwableClass)(it) } - override fun hasEventMatching(level: Level, regex: Regex, throwableClass: KClass): Log4jRuleAssert = + override fun hasEventMatching(level: Level, regex: Regex, throwableClass: KClass): 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()) } @@ -282,10 +282,10 @@ class Log4jRuleAssert(actual: List) : LogRuleAssert): Log4jRuleAssert = Log4jRuleAssert(events).withRepresentation(Log4jRepresentation()) + fun assertThat(events: List): 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) diff --git a/src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRepresentation.kt b/src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRepresentation.kt index a2b7ace..354eec3 100644 --- a/src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRepresentation.kt +++ b/src/main/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRepresentation.kt @@ -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 diff --git a/src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRuleAssert.kt b/src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackAssert.kt similarity index 77% rename from src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRuleAssert.kt rename to src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackAssert.kt index a45437f..a3e482e 100644 --- a/src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRuleAssert.kt +++ b/src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackAssert.kt @@ -24,238 +24,238 @@ import org.assertj.core.error.ShouldNotContainCharSequence.shouldNotContain import org.assertj.core.util.Objects.areEqual import kotlin.reflect.KClass -class LogbackRuleAssert(actual: List) : LogRuleAssert(actual) { +class LogbackAssert(actual: List) : LogRuleAssert(actual) { - override fun hasInfo(): LogbackRuleAssert = + override fun hasInfo(): LogbackAssert = hasEvent(Level.INFO) - override fun hasInfo(predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert = + override fun hasInfo(predicate: (ILoggingEvent) -> Boolean): LogbackAssert = hasEvent(Level.INFO, predicate) - override fun hasInfo(message: String): LogbackRuleAssert = + override fun hasInfo(message: String): LogbackAssert = hasEvent(Level.INFO, message) - override fun hasInfo(message: String, throwable: Throwable): LogbackRuleAssert = + override fun hasInfo(message: String, throwable: Throwable): LogbackAssert = hasEvent(Level.INFO, message, throwable) - override fun hasInfo(message: String, throwableClass: Class): LogbackRuleAssert = + override fun hasInfo(message: String, throwableClass: Class): LogbackAssert = hasEvent(Level.INFO, message, throwableClass) - override fun hasInfo(message: String, throwableClass: KClass): LogbackRuleAssert = + override fun hasInfo(message: String, throwableClass: KClass): LogbackAssert = hasEvent(Level.INFO, message, throwableClass) - override fun hasInfoContaining(vararg messages: String): LogbackRuleAssert = + override fun hasInfoContaining(vararg messages: String): LogbackAssert = hasEventContaining(Level.INFO, *messages) - override fun hasInfoMatching(regex: Regex): LogbackRuleAssert = + override fun hasInfoMatching(regex: Regex): LogbackAssert = hasEventMatching(Level.INFO, regex) - override fun hasInfoMatching(regex: Regex, throwable: Throwable): LogbackRuleAssert = + override fun hasInfoMatching(regex: Regex, throwable: Throwable): LogbackAssert = hasEventMatching(Level.INFO, regex, throwable) - override fun hasInfoMatching(regex: Regex, throwableClass: Class): LogbackRuleAssert = + override fun hasInfoMatching(regex: Regex, throwableClass: Class): LogbackAssert = hasEventMatching(Level.INFO, regex, throwableClass) - override fun hasInfoMatching(regex: Regex, throwableClass: KClass): LogbackRuleAssert = + override fun hasInfoMatching(regex: Regex, throwableClass: KClass): LogbackAssert = hasEventMatching(Level.INFO, regex, throwableClass) - override fun hasNoInfo(): LogbackRuleAssert = + override fun hasNoInfo(): LogbackAssert = hasNoEvent(Level.INFO) - override fun hasNoInfo(predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert = + override fun hasNoInfo(predicate: (ILoggingEvent) -> Boolean): LogbackAssert = hasNoEvent(Level.INFO, predicate) - override fun hasNoInfo(message: String): LogbackRuleAssert = + override fun hasNoInfo(message: String): LogbackAssert = hasNoEvent(Level.INFO, message) - override fun hasNoInfoContaining(vararg messages: String): LogbackRuleAssert = + override fun hasNoInfoContaining(vararg messages: String): LogbackAssert = hasNoEventContaining(Level.INFO, *messages) - override fun hasNoInfoMatching(regex: Regex): LogbackRuleAssert = + override fun hasNoInfoMatching(regex: Regex): LogbackAssert = hasNoEventMatching(Level.INFO, regex) - override fun hasWarn(): LogbackRuleAssert = + override fun hasWarn(): LogbackAssert = hasEvent(Level.WARN) - override fun hasWarn(predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert = + override fun hasWarn(predicate: (ILoggingEvent) -> Boolean): LogbackAssert = hasEvent(Level.WARN, predicate) - override fun hasWarn(message: String): LogbackRuleAssert = + override fun hasWarn(message: String): LogbackAssert = hasEvent(Level.WARN, message) - override fun hasWarn(message: String, throwable: Throwable): LogbackRuleAssert = + override fun hasWarn(message: String, throwable: Throwable): LogbackAssert = hasEvent(Level.WARN, message, throwable) - override fun hasWarn(message: String, throwableClass: Class): LogbackRuleAssert = + override fun hasWarn(message: String, throwableClass: Class): LogbackAssert = hasEvent(Level.WARN, message, throwableClass) - override fun hasWarn(message: String, throwableClass: KClass): LogbackRuleAssert = + override fun hasWarn(message: String, throwableClass: KClass): LogbackAssert = hasEvent(Level.WARN, message, throwableClass) - override fun hasWarnContaining(vararg messages: String): LogbackRuleAssert = + override fun hasWarnContaining(vararg messages: String): LogbackAssert = hasEventContaining(Level.WARN, *messages) - override fun hasWarnMatching(regex: Regex): LogbackRuleAssert = + override fun hasWarnMatching(regex: Regex): LogbackAssert = hasEventMatching(Level.WARN, regex) - override fun hasWarnMatching(regex: Regex, throwable: Throwable): LogbackRuleAssert = + override fun hasWarnMatching(regex: Regex, throwable: Throwable): LogbackAssert = hasEventMatching(Level.WARN, regex, throwable) - override fun hasWarnMatching(regex: Regex, throwableClass: Class): LogbackRuleAssert = + override fun hasWarnMatching(regex: Regex, throwableClass: Class): LogbackAssert = hasEventMatching(Level.WARN, regex, throwableClass) - override fun hasWarnMatching(regex: Regex, throwableClass: KClass): LogbackRuleAssert = + override fun hasWarnMatching(regex: Regex, throwableClass: KClass): LogbackAssert = hasEventMatching(Level.WARN, regex, throwableClass) - override fun hasNoWarn(): LogbackRuleAssert = + override fun hasNoWarn(): LogbackAssert = hasNoEvent(Level.WARN) - override fun hasNoWarn(predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert = + override fun hasNoWarn(predicate: (ILoggingEvent) -> Boolean): LogbackAssert = hasNoEvent(Level.WARN, predicate) - override fun hasNoWarn(message: String): LogbackRuleAssert = + override fun hasNoWarn(message: String): LogbackAssert = hasNoEvent(Level.WARN, message) - override fun hasNoWarnContaining(vararg messages: String): LogbackRuleAssert = + override fun hasNoWarnContaining(vararg messages: String): LogbackAssert = hasNoEventContaining(Level.WARN, *messages) - override fun hasNoWarnMatching(regex: Regex): LogbackRuleAssert = + override fun hasNoWarnMatching(regex: Regex): LogbackAssert = hasNoEventMatching(Level.WARN, regex) - override fun hasError(): LogbackRuleAssert = + override fun hasError(): LogbackAssert = hasEvent(Level.ERROR) - override fun hasError(predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert = + override fun hasError(predicate: (ILoggingEvent) -> Boolean): LogbackAssert = hasEvent(Level.ERROR, predicate) - override fun hasError(message: String): LogbackRuleAssert = + override fun hasError(message: String): LogbackAssert = hasEvent(Level.ERROR, message) - override fun hasError(message: String, throwable: Throwable): LogbackRuleAssert = + override fun hasError(message: String, throwable: Throwable): LogbackAssert = hasEvent(Level.ERROR, message, throwable) - override fun hasError(message: String, throwableClass: Class): LogbackRuleAssert = + override fun hasError(message: String, throwableClass: Class): LogbackAssert = hasEvent(Level.ERROR, message, throwableClass) - override fun hasError(message: String, throwableClass: KClass): LogbackRuleAssert = + override fun hasError(message: String, throwableClass: KClass): LogbackAssert = hasEvent(Level.ERROR, message, throwableClass) - override fun hasErrorContaining(vararg messages: String): LogbackRuleAssert = + override fun hasErrorContaining(vararg messages: String): LogbackAssert = hasEventContaining(Level.ERROR, *messages) - override fun hasErrorMatching(regex: Regex): LogbackRuleAssert = + override fun hasErrorMatching(regex: Regex): LogbackAssert = hasEventMatching(Level.ERROR, regex) - override fun hasErrorMatching(regex: Regex, throwable: Throwable): LogbackRuleAssert = + override fun hasErrorMatching(regex: Regex, throwable: Throwable): LogbackAssert = hasEventMatching(Level.ERROR, regex, throwable) - override fun hasErrorMatching(regex: Regex, throwableClass: Class): LogbackRuleAssert = + override fun hasErrorMatching(regex: Regex, throwableClass: Class): LogbackAssert = hasEventMatching(Level.ERROR, regex, throwableClass) - override fun hasErrorMatching(regex: Regex, throwableClass: KClass): LogbackRuleAssert = + override fun hasErrorMatching(regex: Regex, throwableClass: KClass): LogbackAssert = hasEventMatching(Level.ERROR, regex, throwableClass) - override fun hasNoError(): LogbackRuleAssert = + override fun hasNoError(): LogbackAssert = hasNoEvent(Level.ERROR) - override fun hasNoError(predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert = + override fun hasNoError(predicate: (ILoggingEvent) -> Boolean): LogbackAssert = hasNoEvent(Level.ERROR, predicate) - override fun hasNoError(message: String): LogbackRuleAssert = + override fun hasNoError(message: String): LogbackAssert = hasNoEvent(Level.ERROR, message) - override fun hasNoErrorContaining(vararg messages: String): LogbackRuleAssert = + override fun hasNoErrorContaining(vararg messages: String): LogbackAssert = hasNoEventContaining(Level.ERROR, *messages) - override fun hasNoErrorMatching(regex: Regex): LogbackRuleAssert = + override fun hasNoErrorMatching(regex: Regex): LogbackAssert = hasNoEventMatching(Level.ERROR, regex) - override fun hasEvent(level: Level): LogbackRuleAssert = + override fun hasEvent(level: Level): LogbackAssert = hasEvent("[$level]", withLevel(level)) - override fun hasEvent(level: Level, predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert = + override fun hasEvent(level: Level, predicate: (ILoggingEvent) -> Boolean): LogbackAssert = hasEvent("$level event matching given predicate") { withLevel(level)(it) && predicate(it) } - override fun hasEvent(level: Level, message: String): LogbackRuleAssert = + override fun hasEvent(level: Level, message: String): LogbackAssert = hasEvent(formatLogMessage(level, message)) { withLevel(level)(it) && withMessage(message)(it) } - override fun hasEvent(level: Level, message: String, throwable: Throwable): LogbackRuleAssert = + override fun hasEvent(level: Level, message: String, throwable: Throwable): LogbackAssert = hasEvent(formatLogMessage(level, message)) { withLevel(level)(it) && withMessage(message)(it) && withThrowable(throwable)(it) } - override fun hasEvent(level: Level, message: String, throwableClass: Class): LogbackRuleAssert = + override fun hasEvent(level: Level, message: String, throwableClass: Class): LogbackAssert = hasEvent(formatLogMessage(level, message)) { withLevel(level)(it) && withMessage(message)(it) && withThrowableClass(throwableClass)(it) } - override fun hasEvent(level: Level, message: String, throwableClass: KClass): LogbackRuleAssert = + override fun hasEvent(level: Level, message: String, throwableClass: KClass): LogbackAssert = hasEvent(level, message, throwableClass.java) - override fun hasEventContaining(level: Level, vararg messages: String): LogbackRuleAssert = + override fun hasEventContaining(level: Level, vararg messages: String): LogbackAssert = hasEvent("$level message containing ${messages.contentToString()}") { withLevel(level)(it) && withMessageContaining(messages)(it) } - override fun hasEventMatching(level: Level, regex: Regex): LogbackRuleAssert = + override fun hasEventMatching(level: Level, regex: Regex): LogbackAssert = hasEvent("$level message matching: $regex") { withLevel(level)(it) && withMessageMatching(regex)(it) } - override fun hasEventMatching(level: Level, regex: Regex, throwable: Throwable): LogbackRuleAssert = + override fun hasEventMatching(level: Level, regex: Regex, throwable: Throwable): LogbackAssert = hasEvent("$level message matching: $regex") { withLevel(level)(it) && withMessageMatching(regex)(it) && withThrowable(throwable)(it) } - override fun hasEventMatching(level: Level, regex: Regex, throwableClass: Class): LogbackRuleAssert = + override fun hasEventMatching(level: Level, regex: Regex, throwableClass: Class): LogbackAssert = hasEvent("$level message matching: $regex") { withLevel(level)(it) && withMessageMatching(regex)(it) && withThrowableClass(throwableClass)(it) } - override fun hasEventMatching(level: Level, regex: Regex, throwableClass: KClass): LogbackRuleAssert = + override fun hasEventMatching(level: Level, regex: Regex, throwableClass: KClass): LogbackAssert = hasEventMatching(level, regex, throwableClass.java) - override fun hasNoEvent(level: Level): LogbackRuleAssert = + override fun hasNoEvent(level: Level): LogbackAssert = hasNoEvent("[$level]", withLevel(level)) - override fun hasNoEvent(level: Level, predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert = + override fun hasNoEvent(level: Level, predicate: (ILoggingEvent) -> Boolean): LogbackAssert = hasNoEvent("$level event matching given predicate") { withLevel(level)(it) && predicate(it) } - override fun hasNoEvent(level: Level, message: String): LogbackRuleAssert = + override fun hasNoEvent(level: Level, message: String): LogbackAssert = hasNoEvent(formatLogMessage(level, message)) { withLevel(level)(it) && withMessage(message)(it) } - override fun hasNoEventContaining(level: Level, vararg messages: String): LogbackRuleAssert = + override fun hasNoEventContaining(level: Level, vararg messages: String): LogbackAssert = hasNoEvent("$level message containing ${messages.contentToString()}") { withLevel(level)(it) && withMessageContaining(messages)(it) } - override fun hasNoEventMatching(level: Level, regex: Regex): LogbackRuleAssert = + override fun hasNoEventMatching(level: Level, regex: Regex): LogbackAssert = hasNoEvent("$level message matching: $regex") { withLevel(level)(it) && withMessageMatching(regex)(it) } - private fun hasEvent(description: String, predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert { + private fun hasEvent(description: String, predicate: (ILoggingEvent) -> Boolean): LogbackAssert { if (actual.none(predicate)) { failWithMessage(shouldContain(formatLogEvents(actual).replace("%", "%%"), description.replace("%", "%%")).create()) } return this } - private fun hasNoEvent(description: String, predicate: (ILoggingEvent) -> Boolean): LogbackRuleAssert { + private fun hasNoEvent(description: String, predicate: (ILoggingEvent) -> Boolean): LogbackAssert { if (actual.any(predicate)) { failWithMessage(shouldNotContain(formatLogEvents(actual).replace("%", "%%"), description.replace("%", "%%")).create()) } @@ -283,10 +283,10 @@ class LogbackRuleAssert(actual: List) : LogRuleAssert): LogbackRuleAssert = LogbackRuleAssert(events).withRepresentation(LogbackRepresentation()) + fun assertThat(events: List): LogbackAssert = LogbackAssert(events).withRepresentation(LogbackRepresentation()) @JvmStatic - fun assertThat(rule: LogbackRule): LogbackRuleAssert = assertThat(rule.events) + fun assertThat(rule: LogbackRule): LogbackAssert = assertThat(rule.events) fun formatLogEvent(event: ILoggingEvent) = formatLogMessage(event.level, event.formattedMessage) diff --git a/src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRepresentation.kt b/src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRepresentation.kt index 3581b51..d9f9ab2 100644 --- a/src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRepresentation.kt +++ b/src/main/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRepresentation.kt @@ -1,8 +1,8 @@ package com.tyro.oss.logtesting.junit4.logback import ch.qos.logback.classic.spi.ILoggingEvent -import com.tyro.oss.logtesting.junit4.logback.LogbackRuleAssert.Companion.formatLogEvent -import com.tyro.oss.logtesting.junit4.logback.LogbackRuleAssert.Companion.formatLogEvents +import com.tyro.oss.logtesting.junit4.logback.LogbackAssert.Companion.formatLogEvent +import com.tyro.oss.logtesting.junit4.logback.LogbackAssert.Companion.formatLogEvents import org.assertj.core.presentation.StandardRepresentation class LogbackRepresentation : StandardRepresentation() { diff --git a/src/test/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRuleTest.kt b/src/test/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRuleTest.kt index c75b143..8562f5a 100644 --- a/src/test/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRuleTest.kt +++ b/src/test/kotlin/com/tyro/oss/logtesting/junit4/log4j/Log4jRuleTest.kt @@ -15,7 +15,7 @@ */ package com.tyro.oss.logtesting.junit4.log4j -import com.tyro.oss.logtesting.junit4.log4j.Log4jRuleAssert.Companion.assertThat +import com.tyro.oss.logtesting.junit4.log4j.Log4jAssert.Companion.assertThat import org.apache.log4j.Level import org.apache.log4j.LogManager import org.assertj.core.api.Assertions.assertThatThrownBy diff --git a/src/test/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRuleTest.kt b/src/test/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRuleTest.kt index f545526..6e5aa51 100644 --- a/src/test/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRuleTest.kt +++ b/src/test/kotlin/com/tyro/oss/logtesting/junit4/logback/LogbackRuleTest.kt @@ -16,7 +16,7 @@ package com.tyro.oss.logtesting.junit4.logback import ch.qos.logback.classic.Level -import com.tyro.oss.logtesting.junit4.logback.LogbackRuleAssert.Companion.assertThat +import com.tyro.oss.logtesting.junit4.logback.LogbackAssert.Companion.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Rule import org.junit.Test