This page is no longer maintained — Please continue to the home page at www.scala-lang.org

MockIto and Generics => Compile error.

1 reply
edmondo1984
Joined: 2011-09-14,
User offline. Last seen 28 weeks 3 days ago.
Dear all,I am striving to make the following code compile
when[java.util.Iterator[OisImpl]](collection.iterator).thenReturn(oisCollection.iterator)
but I obtain:
error: overloaded method value thenReturn with alternatives:(java.util.Iterator[OisImpl],<repeated...>[java.util.Iterator[OisImpl]])org.mockito.stubbing.OngoingStubbing[java.util.Iterator[OisImpl]] <and> (java.util.Iterator[OisImpl])org.mockito.stubbing.OngoingStubbing[java.util.Iterator[OisImpl]]cannot be applied to (t: Iterator[OisImpl])when[java.util.Iterator[OisImpl]](collection.iterator).thenReturn(t=oisCollection.iterator)

I have tried also without specifiying the type and let the inferer find it, but I got the same error :(
Do you have any suggestions?
Best RegardsEdmondo
Artie Pesh-Imam
Joined: 2011-07-18,
User offline. Last seen 1 day 4 hours ago.
MockIto and Generics => Compile error.
Hi Edmundo,
I ran into this problem when trying to use Mockito recently. It seems there's an issue with interop between java and scala here. The method thenReturn is overloaded by either taking a single param or a varargs. Java can handle this but Scala cannot. 
See this ticket for a more detailed explanation: https://issues.scala-lang.org/browse/SI-2991
-a
On Mon, Feb 6, 2012 at 6:53 AM, Edmondo Porcu <edmondo [dot] porcu [at] gmail [dot] com> wrote:
Dear all,I am striving to make the following code compile
when[java.util.Iterator[OisImpl]](collection.iterator).thenReturn(oisCollection.iterator)
but I obtain:
error: overloaded method value thenReturn with alternatives:(java.util.Iterator[OisImpl],<repeated...>[java.util.Iterator[OisImpl]])org.mockito.stubbing.OngoingStubbing[java.util.Iterator[OisImpl]] <and> (java.util.Iterator[OisImpl])org.mockito.stubbing.OngoingStubbing[java.util.Iterator[OisImpl]]cannot be applied to (t: Iterator[OisImpl])when[java.util.Iterator[OisImpl]](collection.iterator).thenReturn(t=oisCollection.iterator)

I have tried also without specifiying the type and let the inferer find it, but I got the same error :(
Do you have any suggestions?
Best RegardsEdmondo


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland