I'm trying to test an object to check and make sure it is indeed a List. This is in a unit test, and I'm using scalatest assertResult
to check like so:
val result: Option[List[String]] = Some(List("A", "List"))
assertResult(classOf[List[String]], "the class should be List of Strings")(result.get.getClass)
This compares result.getClass
to classOf[List[String]]
and checks equality that way. However, it turns out that result
is actually a ::
as evidenced by the error message from scalatest:
Expected class scala.collection.immutable.List, but got class scala.collection.immutable.$colon$colon the class should be List of Strings
How can I truly check to see if its a List
?