File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
core/src/test/scala/app/softnetwork/elastic/client Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ package app .softnetwork .elastic .client
2+
3+ import org .mockito .{ArgumentCaptor , MockitoSugar }
4+ import org .scalatest .matchers .should .Matchers
5+ import org .slf4j .Logger
6+
7+ trait LogVerificationHelper { _ : Matchers with MockitoSugar =>
8+ def captureAndVerifyLog (
9+ logger : Logger ,
10+ level : String ,
11+ expectedMessages : String *
12+ )(implicit pos : org.scalactic.source.Position ): Unit = {
13+ import scala .jdk .CollectionConverters ._
14+
15+ val captor : ArgumentCaptor [String ] = ArgumentCaptor .forClass(classOf [String ])
16+
17+ level match {
18+ case " info" => verify(logger, atLeastOnce).info(captor.capture())
19+ case " error" => verify(logger, atLeastOnce).error(captor.capture())
20+ case " warn" => verify(logger, atLeastOnce).warn(captor.capture())
21+ case " debug" => verify(logger, atLeastOnce).debug(captor.capture())
22+ }
23+
24+ val allMessages = captor.getAllValues.asScala.mkString(" \n " )
25+
26+ expectedMessages.foreach { expected =>
27+ withClue(s " Expected message not found: ' $expected' \n All messages: \n $allMessages\n " ) {
28+ allMessages should include(expected)
29+ }
30+ }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments