[Scala] How do I satisfy IDEA's expectation that my scala class's companion object's declaration be tested?

    case class Point(x: Double = 0,
                     y: Double = 0,
                     z: Double = 0) extends Point3D(x, y, z) {


      def +(that: Point): Point = new Point(x + that.x, y + that.y, z + that.z)
      def -(that: Point): Point = new Point(x - that.x, y - that.y, z - that.z)
      def *(that: Point): Point = new Point(x * that.x, y * that.y, z * that.z)
      def /(that: Point): Point = new Point(x / that.x, y / that.y, z / that.z)
    }

    object Point {
      def apply(p3d: Point3D) = new Point(p3d.getX, p3d.getY, p3d.getZ)
    }


IntelliJ is giving this code 92% coverage because the line `object Point {` is being counted in coverage, but I cannot figure out why or how to satisfy it's expectation. I have tried comparing it to something, tried adding another method and calling that... No such luck, and I am out of ideas.

Here is the test code. Any help would be much appreciated!

    import org.scalatest._

    class test_Point extends FlatSpec with Matchers {

      val u = Point(100, 200, 300)
      val v = Point(623, -85, 300)

      it should "supply zero-valued defaults" in {
        val p = Point()
        p.x should be (0)
        p.y should be (0)
        p.z should be (0)
      }

      it should "be constructable from base class" in {
        val p = Point(new Point3D(0, 0, 0))
      }

      it should "implement + operator" in {
        val w = Point(u.x+v.x, u.y+v.y, u.z+v.z)
        u + v should be (w)
      }

      it should "implement - operator" in {
        val w = Point(u.x-v.x, u.y-v.y, u.z-v.z)
        u - v should be (w)
      }

      it should "implement * operator" in {
        val w = Point(u.x*v.x, u.y*v.y, u.z*v.z)
        u * v should be (w)
      }

      it should "implement / operator" in {
        val w = Point(u.x/v.x, u.y/v.y, u.z/v.z)
        u / v should be (w)
      }
    }

0
1 comment

Hi, Elizabeth,


I think the problem is in unapply method, which is not tested, but was implicitly generated by compiler.
I think it's Usability problem of IntelliJ IDEA trying to calculate coverage over synthetic members. I'll ask responsible developer to check that.

Best regards,
Alexander Podkhalyuzin.

0

Please sign in to leave a comment.