Accepted answer

The problem is that com.typesafe.scalalogging.Logger class cannot be mocked because it's final, but we still can mock underlying org.slf4j.Logger.

import org.scalatest.mockito.MockitoSugar
import org.slf4j.{Logger => UnderlyingLogger}
import com.typesafe.scalalogging.Logger
import org.scalatest.{Matchers, WordSpec, FlatSpec}
import org.mockito.Mockito._

class TaskProcessorSpec extends FlatSpec with Matchers with MockitoSugar {

  "TaskProcessor" should "test logging" in {

    val mockLogger = mock[UnderlyingLogger]

    val testable = new TaskProcessor {
      override lazy val logger = Logger(mockLogger)

    verify(mockLogger).info("Test logging")

Related Query

More Query from same tag