paulbutcher / ScalaMock

Native Scala mocking framework
http://scalamock.org/
MIT License
505 stars 100 forks source link

compilation error when mocking classes defined inside traits #198

Open vglushak opened 7 years ago

vglushak commented 7 years ago

ScalaMock Version (e.g. 3.5.0)

3.5.0

Scala Version (e.g. 2.12)

2.11

Runtime (JVM or JS)

JVM

Please describe the expected behavior of the issue

Mock should be created correctly. No exceptions thrown.

Please provide a description of what actually happens

Compilation exception is thrown when pass as parameter a List of internal classes.

[error] method method overrides nothing.
[error] Note: the super classes of <$anon: services.assessmentcentre.Some> contain the following, non final members named method:
[error] def method: ((i: Long, p: List[_10.Param])Unit) forSome { val _10: services.assessmentcentre.Some{val mock$special$mockName: String; override def method(i: Long,p: List[Some.this.Param]): Unit; val mock$method$0: org.scalamock.function.MockFunction2[Long,List[Some.this.Param],Unit]} }
[error]     val mockSome = mock[Some]
[error]                        ^
[error] one error found
[error] (test:compileIncremental) Compilation failed

Reproducible Test Case


trait Some {
  case class Param(name: String)
  def method(i: Long, p: List[Param]): Unit = ???
}

// in test
val mockSome = mock[Some] 
// will fail to compile

Woraround: Move Param case class outside or at least to object with the same name.

barkhorn commented 7 years ago

Thanks for raising this. There are some patterns where the macro based mocks struggle and this looks like another bug related to this - meaning it will be hard if not impossible to fix before our switch to scala.meta. Can you check if you have more success using the Proxy mocks? Also, you may want to upgrade to 3.6.0.