I have a question about using FunSuite with Matchers.
I'm trying to compare to lists of objects so I tried doing this:
orders2 should be(tiOrdersList2)
where orders2 and tiOrdersList2 are scala.List[MyObject]
This match fails miserably, so I tried with
orders2.toSeq should be (tiOrdersList2.toSeq)
no luck
then I tried matching the single items
orders2(0) should be (tiOrdersList2(0))
no luck again
at the end I found that to make it work for the single object I had to use "===" and going back to the first case I managed to get this working:
orders2 === tiOrdersList2
I can't understand what is the difference here. I imagine that the "should be" matcher is stricter than "===" but I can't see why. Can anyone explain that to me?
NOTE: I want to point out that MyObject has various properties of different java based types, including float. could be that the reason?
UPDATE I checked the matcher with simple classes (see snippet below) and if I override the equals method on my own, also the "should be" works, so the main question is what kind of comparison is "===" doing?
import org.scalatest.{Matchers, FunSuite}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class blahSuite extends FunSuite with Matchers
{
test("extractSessions") {
new Object1 === (new Object1)
new Object2 === (new Object2)
new Object1 shouldEqual (new Object1)
new Object2 should be (new Object2)
}
class Object1 {
val pippo: java.lang.String = "blah"
val pappo:java.lang.Long = 0l
override def toString(): String = {
s"$pippo, $pappo"
}
}
class Object2 {
val pippo: java.lang.String = "blah"
val pappo:java.lang.Long = 0l
val pluto:java.lang.Float = 0.0f
override def toString(): String = {
s"$pippo, $pappo, $pluto"
}
}
}
UPDATE2 it seems that "===" compares very loosely: I tried with other instances where the content of an object is different (i.e. different "pippo" strings) and it tells me they are the same. So it seems it compares the class types rather than doing some magic with reflection... I'm getting more and more confused about this and starting to think that I should implement my equals method and forget about this...