Skip to content

Commit cf35016

Browse files
committed
Clean up test cases
1 parent 6426184 commit cf35016

File tree

1 file changed

+67
-34
lines changed

1 file changed

+67
-34
lines changed

src/test/scala/com/typesafe/scalalogging/LoggerSpec.scala

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,6 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
6161
verify(underlying).error("msg {} {}", List(arg1, arg2): _*)
6262
}
6363

64-
"call the underlying logger's error method with the string representation AnyVal arguments" in {
65-
val f = fixture(_.isErrorEnabled, true)
66-
import f._
67-
logger.error(s"msg ${1}")
68-
verify(underlying).error("msg {}", 1.toString)
69-
}
70-
71-
"call the underlying logger's error method escaping literal format anchors" in {
72-
val f = fixture(_.isErrorEnabled, true)
73-
import f._
74-
logger.error(s"foo {} bar $arg1")
75-
verify(underlying).error("foo \\{} bar {}", arg1)
76-
}
77-
"call the underlying logger's error method without escaping format anchors when the message has no interpolations" in {
78-
val f = fixture(_.isErrorEnabled, true)
79-
import f._
80-
logger.error(s"foo {} bar")
81-
verify(underlying).error("foo {} bar")
82-
}
83-
"call the underlying logger's error method when the interpolated string contains escape sequences" in {
84-
val f = fixture(_.isErrorEnabled, true)
85-
import f._
86-
logger.error(s"foo\nbar $arg1")
87-
verify(underlying).error(s"foo\nbar {}", arg1)
88-
}
89-
"call the underlying logger's error method when the interpolated string is triple quoted and contains escape sequences" in {
90-
val f = fixture(_.isErrorEnabled, true)
91-
import f._
92-
logger.error(s"""foo\nbar $arg1""")
93-
verify(underlying).error(s"""foo\nbar {}""", arg1)
94-
}
9564
}
9665

9766
"Calling error with a message and cause" should {
@@ -154,6 +123,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
154123
verify(underlying, never).warn(anyString)
155124
}
156125
}
126+
157127
"Calling warn with an interpolated message" should {
158128

159129
"call the underlying logger's warn method if the warn level is enabled" in {
@@ -162,6 +132,13 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
162132
logger.warn(s"msg $arg1 $arg2 $arg3")
163133
verify(underlying).warn("msg {} {} {}", arg1, arg2, arg3)
164134
}
135+
136+
"call the underlying logger's warn method with two arguments if the warn level is enabled" in {
137+
val f = fixture(_.isWarnEnabled, true)
138+
import f._
139+
logger.warn(s"msg $arg1 $arg2")
140+
verify(underlying).warn("msg {} {}", List(arg1, arg2): _*)
141+
}
165142
}
166143

167144
"Calling warn with a message and cause" should {
@@ -224,6 +201,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
224201
verify(underlying, never).info(anyString)
225202
}
226203
}
204+
227205
"Calling info with an interpolated message" should {
228206

229207
"call the underlying logger's info method if the info level is enabled" in {
@@ -232,6 +210,13 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
232210
logger.info(s"msg $arg1 $arg2 $arg3")
233211
verify(underlying).info("msg {} {} {}", arg1, arg2, arg3)
234212
}
213+
214+
"call the underlying logger's info method with two arguments if the info level is enabled" in {
215+
val f = fixture(_.isInfoEnabled, true)
216+
import f._
217+
logger.info(s"msg $arg1 $arg2")
218+
verify(underlying).info("msg {} {}", List(arg1, arg2): _*)
219+
}
235220
}
236221

237222
"Calling info with a message and cause" should {
@@ -303,11 +288,11 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
303288
verify(underlying).debug("msg {} {} {}", arg1, arg2, arg3)
304289
}
305290

306-
"call the underlying logger's debug method with the string representation of AnyVal arguments" in {
291+
"call the underlying logger's debug method with two arguments if the debug level is enabled" in {
307292
val f = fixture(_.isDebugEnabled, true)
308293
import f._
309-
logger.debug(s"msg ${1}")
310-
verify(underlying).debug("msg {}", 1.toString)
294+
logger.debug(s"msg $arg1 $arg2")
295+
verify(underlying).debug("msg {} {}", List(arg1, arg2): _*)
311296
}
312297
}
313298

@@ -371,6 +356,7 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
371356
verify(underlying, never).trace(anyString)
372357
}
373358
}
359+
374360
"Calling trace with an interpolated message" should {
375361

376362
"call the underlying logger's trace method if the trace level is enabled" in {
@@ -379,6 +365,13 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
379365
logger.trace(s"msg $arg1 $arg2 $arg3")
380366
verify(underlying).trace("msg {} {} {}", arg1, arg2, arg3)
381367
}
368+
369+
"call the underlying logger's trace method with two arguments if the trace level is enabled" in {
370+
val f = fixture(_.isTraceEnabled, true)
371+
import f._
372+
logger.trace(s"msg $arg1 $arg2")
373+
verify(underlying).trace("msg {} {}", List(arg1, arg2): _*)
374+
}
382375
}
383376

384377
"Calling trace with a message and cause" should {
@@ -423,6 +416,46 @@ class LoggerSpec extends WordSpec with Matchers with MockitoSugar {
423416
}
424417
}
425418

419+
// Interpolator destructuring corner cases
420+
421+
"Logging a message using the standard string interpolator" should {
422+
423+
"call the underlying format method with the string representation of AnyVal arguments" in {
424+
val f = fixture(_.isErrorEnabled, true)
425+
import f._
426+
logger.error(s"msg ${1}")
427+
verify(underlying).error("msg {}", 1.toString)
428+
}
429+
430+
"call the underlying format method escaping literal format anchors" in {
431+
val f = fixture(_.isErrorEnabled, true)
432+
import f._
433+
logger.error(s"foo {} bar $arg1")
434+
verify(underlying).error("foo \\{} bar {}", arg1)
435+
}
436+
437+
"call the underlying method without escaping format anchors when the message has no interpolations" in {
438+
val f = fixture(_.isErrorEnabled, true)
439+
import f._
440+
logger.error(s"foo {} bar")
441+
verify(underlying).error("foo {} bar")
442+
}
443+
444+
"call the underlying format method when the interpolated string contains escape sequences" in {
445+
val f = fixture(_.isErrorEnabled, true)
446+
import f._
447+
logger.error(s"foo\nbar $arg1")
448+
verify(underlying).error(s"foo\nbar {}", arg1)
449+
}
450+
451+
"call the underlying format method when the interpolated string is triple quoted and contains escape sequences" in {
452+
val f = fixture(_.isErrorEnabled, true)
453+
import f._
454+
logger.error(s"""foo\nbar $arg1""")
455+
verify(underlying).error(s"""foo\nbar {}""", arg1)
456+
}
457+
}
458+
426459
"Serializing Logger" should {
427460

428461
def serialize(logger: Logger): Array[Byte] = {

0 commit comments

Comments
 (0)