diff --git a/src/main/scala/com/sksamuel/scapegoat/Level.scala b/src/main/scala/com/sksamuel/scapegoat/Level.scala index 2d3ad314..bf2b9674 100644 --- a/src/main/scala/com/sksamuel/scapegoat/Level.scala +++ b/src/main/scala/com/sksamuel/scapegoat/Level.scala @@ -64,7 +64,7 @@ object Levels { case "error" => Error case "warning" => Warning case "info" => Info - case "ignore" => Ignore + case "ignore" => Ignore case _ => throw new IllegalArgumentException(s"Unrecognised level '$name'") } } diff --git a/src/test/scala/com/sksamuel/scapegoat/LevelsTest.scala b/src/test/scala/com/sksamuel/scapegoat/LevelsTest.scala new file mode 100644 index 00000000..e44de3cc --- /dev/null +++ b/src/test/scala/com/sksamuel/scapegoat/LevelsTest.scala @@ -0,0 +1,69 @@ +package com.sksamuel.scapegoat + +import org.scalatest.freespec.AnyFreeSpec +import org.scalatest.matchers.should.Matchers + +class LevelsTest extends AnyFreeSpec with Matchers { + "Levels" - { + "#fromName" - { + "should return correct object" - { + "for 'error'" in { + Levels.fromName("error") should be(Levels.Error) + } + + "for 'warning'" in { + Levels.fromName("warning") should be(Levels.Warning) + } + + "for 'info'" in { + Levels.fromName("info") should be(Levels.Info) + } + + "for 'ignore'" in { + Levels.fromName("ignore") should be(Levels.Ignore) + } + } + + "throw an exception when uunknown level is provided" in { + the[IllegalArgumentException] thrownBy Levels.fromName( + "UNKNOWN" + ) should have message "Unrecognised level 'UNKNOWN'" + } + } + } + + "Level" - { + "#higherOrEqual" - { + "should be true for levels with higher weight" - { + val levels = Seq(Levels.Ignore, Levels.Info, Levels.Warning, Levels.Error) + + "for ignore" in { + levels.map(other => + Levels.Ignore.higherOrEqualTo(other) + ) should contain theSameElementsInOrderAs Seq(true, false, false, false) + } + + "for info" in { + levels.map(other => Levels.Info.higherOrEqualTo(other)) should contain theSameElementsInOrderAs Seq( + true, + true, + false, + false + ) + } + + "for warning" in { + levels.map(other => + Levels.Warning.higherOrEqualTo(other) + ) should contain theSameElementsInOrderAs Seq(true, true, true, false) + } + + "for error" in { + levels.map(other => + Levels.Error.higherOrEqualTo(other) + ) should contain theSameElementsInOrderAs Seq(true, true, true, true) + } + } + } + } +}