Cannot mock classes that inherit from superclass. #14

Closed
dhinojosa opened this Issue Mar 25, 2012 · 1 comment

Comments

Projects
None yet
2 participants

Given the following classes, ScalaMock is unable to create a mock for CompilationAlbum. Assume that annotation have been placed already on the Dummy object.

package com.oreilly.testingscala

import org.joda.time.Period

class Album (val title: String, val year: Int, val tracks: Option[List[Track]], val acts: Act*) {
  require(acts.size > 0)

  def this(title: String, year: Int, acts: Act*) = this(title, year, None, acts:_*)

  def ageFrom(now: Int) = now - year

  def period = tracks.getOrElse(Nil).map(_.period).foldLeft(Period.ZERO)(_.plus(_))

  override def toString = ("Album" + "[" + title + "]")
}
package com.oreilly.testingscala

class CompilationAlbum(override val title: String,
                       override val year: Int,
                       val tracksAndActs: (Track, List[Act])*)
  extends Album(title, year,
                Some(tracksAndActs.map(_._1).toList),
                tracksAndActs.flatMap(_._2).distinct:_*)

The above causes the following messages complaining about override tags that are required:

[info] Compiling 19 Scala sources to /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/mock-classes...
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:57: overriding lazy value mock$0 in class Album of type org.scalamock.MockFunction;
[error]  lazy value mock$0 needs `override' modifier
[error]   protected lazy val mock$0 = new org.scalamock.MockConstructor[com.oreilly.testingscala.CompilationAlbum](factory, Symbol("this"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:58: overriding lazy value mock$1 in class Album of type org.scalamock.MockFunction;
[error]  lazy value mock$1 needs `override' modifier
[error]   protected lazy val mock$1 = new org.scalamock.MockFunction(factory, Symbol("tracksAndActs"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:59: overriding lazy value mock$2 in class Album of type org.scalamock.MockConstructor[com.oreilly.testingscala.Album];
[error]  lazy value mock$2 needs `override' modifier
[error]   protected lazy val mock$2 = new org.scalamock.MockFunction(factory, Symbol("year"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:60: overriding lazy value mock$3 in class Album of type org.scalamock.MockConstructor[com.oreilly.testingscala.Album];
[error]  lazy value mock$3 needs `override' modifier
[error]   protected lazy val mock$3 = new org.scalamock.MockFunction(factory, Symbol("title"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:61: overriding lazy value mock$4 in class Album of type org.scalamock.MockFunction;
[error]  lazy value mock$4 needs `override' modifier
[error]   protected lazy val mock$4 = new org.scalamock.MockFunction(factory, Symbol("period"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:62: overriding lazy value mock$5 in class Album of type org.scalamock.MockFunction;
[error]  lazy value mock$5 needs `override' modifier
[error]   protected lazy val mock$5 = new org.scalamock.MockFunction(factory, Symbol("ageFrom"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:63: overriding lazy value mock$6 in class Album of type org.scalamock.MockFunction;
[error]  lazy value mock$6 needs `override' modifier
[error]   protected lazy val mock$6 = new org.scalamock.MockConstructor[com.oreilly.testingscala.Album](factory, Symbol("this"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:64: overriding lazy value mock$7 in class Album of type org.scalamock.MockFunction;
[error]  lazy value mock$7 needs `override' modifier
[error]   protected lazy val mock$7 = new org.scalamock.MockConstructor[com.oreilly.testingscala.Album](factory, Symbol("this"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:65: overriding lazy value mock$8 in class Album of type org.scalamock.MockConstructor[java.lang.Object];
[error]  lazy value mock$8 needs `override' modifier
[error]   protected lazy val mock$8 = new org.scalamock.MockFunction(factory, Symbol("acts"))
[error]                      ^
[error] /home/danno/testing_scala_book.svn/testingscala/target/scala-2.9.1/src_managed/mock/scala/com/oreilly/testingscala/CompilationAlbum.scala:3: overriding value expects in trait Mock$Album of type java.lang.Object{def period: org.scalamock.TypeSafeExpectation0[org.joda.time.Period]; def ageFrom(now: org.scalamock.MockParameter[Int]): org.scalamock.TypeSafeExpectation1[Int,Int]; def ageFrom(matcher: org.scalamock.MockMatcher1[Int]): org.scalamock.TypeSafeExpectation1[Int,Int]; def newInstance(title: org.scalamock.MockParameter[String],year: org.scalamock.MockParameter[Int],acts: org.scalamock.MockParameter[com.oreilly.testingscala.Act]*): org.scalamock.Expectation; def newInstance(title: org.scalamock.MockParameter[String],year: org.scalamock.MockParameter[Int],tracks: org.scalamock.MockParameter[Option[List[com.oreilly.testingscala.Track]]],acts: org.scalamock.MockParameter[com.oreilly.testingscala.Act]*): org.scalamock.Expectation; def acts: org.scalamock.TypeSafeExpectation0[Seq[com.oreilly.testingscala.Act]]; def tracks: org.scalamock.TypeSafeExpectation0[Option[List[com.oreilly.testingscala.Track]]]; def year: org.scalamock.TypeSafeExpectation0[Int]; def title: org.scalamock.TypeSafeExpectation0[String]; def newInstance(): org.scalamock.Expectation};
[error]  value expects in trait Mock$CompilationAlbum of type java.lang.Object{def newInstance(title: org.scalamock.MockParameter[String],year: org.scalamock.MockParameter[Int],tracksAndActs: org.scalamock.MockParameter[(com.oreilly.testingscala.Track, List[com.oreilly.testingscala.Act])]*): org.scalamock.Expectation; def tracksAndActs: org.scalamock.TypeSafeExpectation0[Seq[(com.oreilly.testingscala.Track, List[com.oreilly.testingscala.Act])]]; def year: org.scalamock.TypeSafeExpectation0[Int]; def title: org.scalamock.TypeSafeExpectation0[String]; def period: org.scalamock.TypeSafeExpectation0[org.joda.time.Period]; def ageFrom(now: org.scalamock.MockParameter[Int]): org.scalamock.TypeSafeExpectation1[Int,Int]; def ageFrom(matcher: org.scalamock.MockMatcher1[Int]): org.scalamock.TypeSafeExpectation1[Int,Int]; def newInstance(title: org.scalamock.MockParameter[String],year: org.scalamock.MockParameter[Int],acts: org.scalamock.MockParameter[com.oreilly.testingscala.Act]*): org.scalamock.Expectation; def newInstance(title: org.scalamock.MockParameter[String],year: org.scalamock.MockParameter[Int],tracks: org.scalamock.MockParameter[Option[List[com.oreilly.testingscala.Track]]],acts: org.scalamock.MockParameter[com.oreilly.testingscala.Act]*): org.scalamock.Expectation; def acts: org.scalamock.TypeSafeExpectation0[Seq[com.oreilly.testingscala.Act]]; def tracks: org.scalamock.TypeSafeExpectation0[Option[List[com.oreilly.testingscala.Track]]]; def newInstance(): org.scalamock.Expectation} needs `override' modifier;
[error]  other members with override errors are: factory
[error] class CompilationAlbum(dummy: org.scalamock.MockConstructorDummy) extends com.oreilly.testingscala.Album with Mock$CompilationAlbum {
[error]       ^
[error] 10 errors found
[error] {file:/home/danno/testing_scala_book.svn/testingscala/}Testing Scala/mock:compile: Compilation failed
Owner

paulbutcher commented Oct 14, 2012

Closing this issue - ScalaMock 3 is moving to using macros instead of a compiler plugin, and I don't propose to fix outstanding issues in ScalaMock 2.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment