easyforgood / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

mockito misses Scala's trait method starting with Scala 2.9.x #340

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Simple case:

   trait A {
     def evilA() { throw new RuntimeException("Fail hard.") }
   }

   class B extends A

   val mocked = Mockito.mock(classOf[B])
   mocked.evilA() // this isn't mocked but runs the method and throws the exception

That's because starting with Scala 2.9.x forwarders to trait methods are marked 
with `ACC_BRIDGE` which are missed by mockito for some reason.

Original issue reported on code.google.com by johannes...@googlemail.com on 3 May 2012 at 2:43

GoogleCodeExporter commented 8 years ago
See also http://stackoverflow.com/questions/7625902/mock-classes-with-traits 
which got me on track with the bridge flag.

Original comment by johannes...@googlemail.com on 3 May 2012 at 2:53

GoogleCodeExporter commented 8 years ago
This seems to be fixed on the Scala side in Scala 2.10:

https://groups.google.com/forum/?fromgroups#!topic/scala-language/Z_iIQIHUaRI

Original comment by johannes...@googlemail.com on 3 May 2012 at 2:59

GoogleCodeExporter commented 8 years ago
Seems like this is fixed even in Scala 2.9.2, so maybe in reality it will soon 
be a non-issue.

Original comment by johannes...@googlemail.com on 3 May 2012 at 3:06

GoogleCodeExporter commented 8 years ago
Cool, thanks for reporting and analyzing the issue.

Actually I don't think anyone in the team knows particarly well Scala, and 
especially how Scala compiler generates the bytecode. Plus we are a bit stuck 
with the bytecode engine, I personnally tried Javassist but found it 
disappointing for our usecases.

That's a personnal opinion, but I tried to work on that matter. And, I have now 
the feeling that new works on a bytecode engine should only target JDK 1.7+ as 
the invokedynamic opcode looks very promising. Yet I might be wrong.

Anyway about Scala, unless some Scala guru, maybe you ;), could help with that, 
we are a bit stuck on the matter if something similar were to happen again.
I'd like to set the issue to Won't Fix, is it ok with you ?

Cheers,
Brice

Original comment by brice.du...@gmail.com on 3 May 2012 at 4:53

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 6 Sep 2012 at 3:45