score:7
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]
when(mockLogger.isInfoEnabled).thenReturn(true)
val testable = new TaskProcessor {
override lazy val logger = Logger(mockLogger)
}
testable.a1()
verify(mockLogger).info("Test logging")
}
}
Source: stackoverflow.com
Related Query
- Unit test LazyLogging using Mockito
- Unit test logger messages using specs2 + scalalogging
- Why is this specs2 test using Mockito passing?
- How to unit test an Akka actor that sends a message to itself, without using Thread.sleep
- Future's .recover not getting called when Exception is thrown in Mockito unit test
- How to Unit Test when using ScalaJ-Http?
- Run Integration test and Unit test using Maven in Scala project
- Using winutils and HBaseMiniCluster to unit test code
- For comprehension not composing steps fully in unit test using Reader
- Perplexing unit test code execution order when using ScalaCheck / ScalaTest clauses
- Scala: How to Unit Test a function I have which makes an API call using mock/stub?
- Using Mockito & Guice to test interfaces with generics in Scala
- Spark unit test compilation error when using Spark testing base
- Test CRUD function in Playframework unit tests using ScalaTest
- Scala Unit Testing using mockito library
- Unit testing Scala using mockito
- Unit test cases for web sockets using akka http
- How can I unit test this Play Scala controller using Specs2?
- What’s the difference between ScalaTest and Scala Specs unit test frameworks?
- How do you share classes between test configurations using SBT
- Use Scala to unit test Java?
- How do I write a scala unit test that ensures compliation fails?
- Is there a Scala unit test tool that integrates well with Maven?
- Compare scala.xml.Elem object in unit test
- How do you unit test Scala in Eclipse?
- How to override guice modules in Playframework unit tests using ScalaTest
- Scala / Lift: How do I write unit tests that test a snippet's response to different parameters
- Unit testing Scala.js: Read test data from file residing in `test/resources`
- UnsatisfiedLinkError: no snappyjava in java.library.path when running Spark MLLib Unit test within Intellij
- Unable to test controller using Action.async
More Query from same tag
- Pattern Match "return" value
- spark count genetic mutations from tsv files
- issue with Blueprints API, addVertex
- Pattern Match on String in Scala
- How to read .csv file using BlobId
- Filter for the list of numbers in slick 3
- Scala Spark Sql - Reading null values from a Hive row
- Apache Spark RDD substitution
- Scala Stream call-by-need (lazy) vs call-by-name
- How to receive a message within a specific case of a receive in Akka actors?
- Java 8 parallel sorting vs Scala parallel sorting
- DocBook sources of "Starting with Lift"
- Fastest way to parse flat, attribute-heavy xml in Java or Scala
- Slick: Read nullable values as option when left join
- How to resolve ambiguous implicit conversion method that takes same input type in Scala?
- My coproduct encoding is ambiguous
- Scala Spark DataFrame : dataFrame.select multiple columns given a Sequence of column names
- Spark Scala: functional difference in notation using $?
- Define a function in Scala that takes an Array of a wildcard as a parameter
- Play & JSON: How to make scala code more concise
- How to sort column of means with Spark SQL?
- Scala Play 2.5 Controller class to serve static HTML
- Commandline menu loop Scala
- Why for-loop with yield accumulates into a Map instead of a List?
- how to find a specific pattern in a file in Scala
- How does Scala compiler handle unused variable values?
- How to find minimum and maximum of cartesian co-ordinates in Scala
- Can't get access to a project's classes / objects from Build.scala
- Are Options and named default arguments like oil and water in a Scala API?
- Converting RDD(Arrary(String,Int) ) into Json in scala