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

Commit

Permalink
Rename junit 5 extension classes
Browse files Browse the repository at this point in the history
  • Loading branch information
steveorourke committed Dec 7, 2018
1 parent 1e67c6c commit a43763a
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import org.assertj.core.api.ObjectAssert
import org.assertj.core.api.ObjectAssertFactory
import kotlin.reflect.KClass

abstract class LogRuleAssert<SELF : LogRuleAssert<SELF, LEVEL, EVENT>, LEVEL, EVENT>(actual: List<EVENT>)
: FactoryBasedNavigableListAssert<SELF, List<EVENT>, EVENT, ObjectAssert<EVENT>>(actual, LogRuleAssert::class.java, ObjectAssertFactory<EVENT>()) {
abstract class LogAssert<SELF : LogAssert<SELF, LEVEL, EVENT>, LEVEL, EVENT>(actual: List<EVENT>)
: FactoryBasedNavigableListAssert<SELF, List<EVENT>, EVENT, ObjectAssert<EVENT>>(actual, LogAssert::class.java, ObjectAssertFactory<EVENT>()) {

abstract fun hasEvent(level: LEVEL): SELF
abstract fun hasEvent(level: LEVEL, predicate: (EVENT) -> Boolean): SELF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.tyro.oss.logtesting
import org.junit.jupiter.api.extension.AfterEachCallback
import org.junit.jupiter.api.extension.BeforeEachCallback

abstract class LogRule<T> : BeforeEachCallback, AfterEachCallback {
abstract class LogCaptor<T> : BeforeEachCallback, AfterEachCallback {

abstract val events: MutableList<T>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package com.tyro.oss.logtesting.junit4.log4j

import com.tyro.oss.logtesting.LogRuleAssert
import com.tyro.oss.logtesting.LogAssert
import org.apache.log4j.Level
import org.apache.log4j.spi.LoggingEvent
import org.assertj.core.error.ShouldContainCharSequence.shouldContain
import org.assertj.core.error.ShouldNotContainCharSequence.shouldNotContain
import org.assertj.core.util.Objects.areEqual
import kotlin.reflect.KClass

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

override fun hasInfo(): Log4jAssert =
hasEvent(Level.INFO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package com.tyro.oss.logtesting.junit4.logback
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.classic.spi.ThrowableProxy
import com.tyro.oss.logtesting.LogRuleAssert
import com.tyro.oss.logtesting.LogAssert
import org.assertj.core.error.ShouldContainCharSequence.shouldContain
import org.assertj.core.error.ShouldNotContainCharSequence.shouldNotContain
import org.assertj.core.util.Objects.areEqual
import kotlin.reflect.KClass

class LogbackAssert(actual: List<ILoggingEvent>) : LogRuleAssert<LogbackAssert, Level, ILoggingEvent>(actual) {
class LogbackAssert(actual: List<ILoggingEvent>) : LogAssert<LogbackAssert, Level, ILoggingEvent>(actual) {

override fun hasInfo(): LogbackAssert =
hasEvent(Level.INFO)
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/tyro/oss/logtesting/log4j/Log4jAssert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package com.tyro.oss.logtesting.log4j

import com.tyro.oss.logtesting.LogRuleAssert
import com.tyro.oss.logtesting.LogAssert
import org.apache.log4j.Level
import org.apache.log4j.spi.LoggingEvent
import org.assertj.core.error.ShouldContainCharSequence.shouldContain
import org.assertj.core.error.ShouldNotContainCharSequence.shouldNotContain
import org.assertj.core.util.Objects.areEqual
import kotlin.reflect.KClass

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

override fun hasInfo(): Log4jAssert =
hasEvent(Level.INFO)
Expand Down Expand Up @@ -285,7 +285,7 @@ class Log4jAssert(actual: List<LoggingEvent>) : LogRuleAssert<Log4jAssert, Level
fun assertThat(events: List<LoggingEvent>): Log4jAssert = Log4jAssert(events).withRepresentation(Log4jRepresentation())

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package com.tyro.oss.logtesting.log4j

import com.tyro.oss.logtesting.LogRule
import com.tyro.oss.logtesting.LogCaptor
import org.apache.log4j.AppenderSkeleton
import org.apache.log4j.LogManager
import org.apache.log4j.Logger
import org.apache.log4j.spi.LoggingEvent
import org.junit.jupiter.api.extension.ExtensionContext
import kotlin.reflect.KClass

class Log4jRule : LogRule<LoggingEvent> {
class Log4jCaptor : LogCaptor<LoggingEvent> {

private val logger: Logger
private lateinit var appender: CapturingAppender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package com.tyro.oss.logtesting.logback
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.classic.spi.ThrowableProxy
import com.tyro.oss.logtesting.LogRuleAssert
import com.tyro.oss.logtesting.LogAssert
import org.assertj.core.error.ShouldContainCharSequence.shouldContain
import org.assertj.core.error.ShouldNotContainCharSequence.shouldNotContain
import org.assertj.core.util.Objects.areEqual
import kotlin.reflect.KClass

class LogbackAssert(actual: List<ILoggingEvent>) : LogRuleAssert<LogbackAssert, Level, ILoggingEvent>(actual) {
class LogbackAssert(actual: List<ILoggingEvent>) : LogAssert<LogbackAssert, Level, ILoggingEvent>(actual) {

override fun hasInfo(): LogbackAssert =
hasEvent(Level.INFO)
Expand Down Expand Up @@ -286,7 +286,7 @@ class LogbackAssert(actual: List<ILoggingEvent>) : LogRuleAssert<LogbackAssert,
fun assertThat(events: List<ILoggingEvent>): LogbackAssert = LogbackAssert(events).withRepresentation(LogbackRepresentation())

@JvmStatic
fun assertThat(rule: LogbackRule): LogbackAssert = assertThat(rule.events)
fun assertThat(logCaptor: LogbackCaptor): LogbackAssert = assertThat(logCaptor.events)

fun formatLogEvent(event: ILoggingEvent) = formatLogMessage(event.level, event.formattedMessage)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package com.tyro.oss.logtesting.logback
import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.AppenderBase
import com.tyro.oss.logtesting.LogRule
import com.tyro.oss.logtesting.LogCaptor
import org.junit.jupiter.api.extension.ExtensionContext
import org.slf4j.LoggerFactory
import kotlin.reflect.KClass

class LogbackRule : LogRule<ILoggingEvent> {
class LogbackCaptor : LogCaptor<ILoggingEvent> {

private val logger: Logger
private lateinit var appender: CapturingAppender
Expand Down
Loading

0 comments on commit a43763a

Please sign in to comment.