Scala and EasyMock

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Scala and EasyMock

victorspivak
I try to use EasyMock (2.4) with Scala(2.7.5) and I got a problem with the following sample: var mock = EasyMock.createNiceMock(classOf[List[String]]).asInstanceOf[List[String]] EasyMock.expect(mock.length()).andReturn(5) EasyMock.replay(mock) mock.length EasyMock.verify(mock) This code does not compiled and complains with the error: "value expect is not a member of object classextenssion.this.EasyMock EasyMock.expect(mock.length()).andReturn(5) All jars are included. When I remove expect statement it complains that there is missing behavior definition. Have you seen such behavior? Thanks, Victor
Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

Jan Lohre
Hi,

I had a quick look at the EasyMock documentation. My suspition came from List beeing a class, not a trait (interface). So you are probably using easymock classextension.

The EasyMock class (from package *.classextension) extends the normal EasyMock class where expect is implemented. I would guess there is no static method "inheritence" in scala, so scalac does not see the expect method.

I could still be wrong, as this was a 5 second guess, I never used EasyMock from Scala and never tried to call "inherited" static methods (somehow I get goosebumps using the word inheritence with static methods, but I have no better one).

Kind regards,
Jan

2009/7/21 victorspivak <[hidden email]>
I try to use EasyMock (2.4) with Scala(2.7.5) and I got a problem with the following sample: var mock = EasyMock.createNiceMock(classOf[List[String]]).asInstanceOf[List[String]] EasyMock.expect(mock.length()).andReturn(5) EasyMock.replay(mock) mock.length EasyMock.verify(mock) This code does not compiled and complains with the error: "value expect is not a member of object classextenssion.this.EasyMock EasyMock.expect(mock.length()).andReturn(5) All jars are included. When I remove expect statement it complains that there is missing behavior definition. Have you seen such behavior? Thanks, Victor

View this message in context: Scala and EasyMock
Sent from the Scala - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

victorspivak
Jan,

Thank you for your reply.  Eventually in the real project I use a trait.  It is not about concrete class vs. interface vs. trait.  It complains for use "expect" method.  I could not understand why Scala compiler complains.  BTW, I use IntelliJ Scala plugin and IntelliJ resolves the expect method.

I switch from EasyMock to Mockito and everything is fine.  I am just curious what wrong is EasyMock in Scala world and what I wromg doing :(

Thanks

Victor

Jan Lohre wrote
Hi,

I had a quick look at the EasyMock documentation. My suspition came from
List beeing a class, not a trait (interface). So you are probably using
easymock classextension.

The EasyMock class (from package *.classextension) extends the normal
EasyMock class where expect is implemented. I would guess there is no static
method "inheritence" in scala, so scalac does not see the expect method.

I could still be wrong, as this was a 5 second guess, I never used EasyMock
from Scala and never tried to call "inherited" static methods (somehow I get
goosebumps using the word inheritence with static methods, but I have no
better one).

Kind regards,
Jan

2009/7/21 victorspivak <victor.spivak@gmail.com>

> I try to use EasyMock (2.4) with Scala(2.7.5) and I got a problem with the
> following sample: var mock =
> EasyMock.createNiceMock(classOf[List[String]]).asInstanceOf[List[String]]
> EasyMock.expect(mock.length()).andReturn(5) EasyMock.replay(mock)
> mock.length EasyMock.verify(mock) This code does not compiled and complains
> with the error: "value expect is not a member of object
> classextenssion.this.EasyMock EasyMock.expect(mock.length()).andReturn(5)
> All jars are included. When I remove expect statement it complains that
> there is missing behavior definition. Have you seen such behavior? Thanks,
> Victor
> ------------------------------
> View this message in context: Scala and EasyMock<http://www.nabble.com/Scala-and-EasyMock-tp24579481p24579481.html>
> Sent from the Scala - User mailing list archive<http://www.nabble.com/Scala---User-f30217.html>at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

Ben Hutchison-2
On Wed, Jul 22, 2009 at 4:49 AM, victorspivak<[hidden email]> wrote:
I am just curious
> what wrong is EasyMock in Scala world and what I wromg doing :(
>

I think Jan has already explained why. Make sure you understand what
he meant by:

"The EasyMock class (from package *.classextension) extends the normal
EasyMock class where expect is implemented. I would guess there is no
static method "inheritence" in scala, so scalac does not see the
expect method."

Ie there are 2 EasyMock classes in EasyMock. One inherits from the
other. Java statics implicitly inherit. Scala's dont (Im guessing
here).

-Ben
Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

Naftoli Gugenheim
In reply to this post by victorspivak
They were talking about allowing extending objects. Would that imply static inheritance? Is that for 2.8 anyway?

-------------------------------------
Ben Hutchison<[hidden email]> wrote:

On Wed, Jul 22, 2009 at 4:49 AM, victorspivak<[hidden email]> wrote:
I am just curious
> what wrong is EasyMock in Scala world and what I wromg doing :(
>

I think Jan has already explained why. Make sure you understand what
he meant by:

"The EasyMock class (from package *.classextension) extends the normal
EasyMock class where expect is implemented. I would guess there is no
static method "inheritence" in scala, so scalac does not see the
expect method."

Ie there are 2 EasyMock classes in EasyMock. One inherits from the
other. Java statics implicitly inherit. Scala's dont (Im guessing
here).

-Ben
Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

victorspivak
In reply to this post by Ben Hutchison-2
Ben,

I've read the Jan response.  But I do not think it explains the behavior that I observe. The mocking of concrete classes is done by classextension package (BTW, I have included it) and if I do not include it the Java compiler compiles the code but during run time it generates an error.  Also I tried to use a trait (in Java world it is an interface) and it does not require classextension.  I still get the same error - could not resolve the expect method.  It is somehow related to the definition of the expect method.  All examples for using EasyMock with Scala that I found in the Net do not use expect method.

Victor
Ben Hutchison wrote
On Wed, Jul 22, 2009 at 4:49 AM, victorspivak<victor.spivak@gmail.com> wrote:
I am just curious
> what wrong is EasyMock in Scala world and what I wromg doing :(
>

I think Jan has already explained why. Make sure you understand what
he meant by:

"The EasyMock class (from package *.classextension) extends the normal
EasyMock class where expect is implemented. I would guess there is no
static method "inheritence" in scala, so scalac does not see the
expect method."

Ie there are 2 EasyMock classes in EasyMock. One inherits from the
other. Java statics implicitly inherit. Scala's dont (Im guessing
here).

-Ben
Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

Ricky Clarkson
I haven't looked into this at all, but it really does seem you've had
the answer handed to you and are ignoring it.  The problem with that
method is that it's static.  Have you tried referring to it as
com.whatever.EasyMock.expect?

2009/7/22 victorspivak <[hidden email]>:

>
> Ben,
>
> I've read the Jan response.  But I do not think it explains the behavior
> that I observe. The mocking of concrete classes is done by classextension
> package (BTW, I have included it) and if I do not include it the Java
> compiler compiles the code but during run time it generates an error.  Also
> I tried to use a trait (in Java world it is an interface) and it does not
> require classextension.  I still get the same error - could not resolve the
> expect method.  It is somehow related to the definition of the expect
> method.  All examples for using EasyMock with Scala that I found in the Net
> do not use expect method.
>
> Victor
>
> Ben Hutchison wrote:
>>
>> On Wed, Jul 22, 2009 at 4:49 AM, victorspivak<[hidden email]>
>> wrote:
>> I am just curious
>>> what wrong is EasyMock in Scala world and what I wromg doing :(
>>>
>>
>> I think Jan has already explained why. Make sure you understand what
>> he meant by:
>>
>> "The EasyMock class (from package *.classextension) extends the normal
>> EasyMock class where expect is implemented. I would guess there is no
>> static method "inheritence" in scala, so scalac does not see the
>> expect method."
>>
>> Ie there are 2 EasyMock classes in EasyMock. One inherits from the
>> other. Java statics implicitly inherit. Scala's dont (Im guessing
>> here).
>>
>> -Ben
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Scala-and-EasyMock-tp24579481p24598399.html
> Sent from the Scala - User mailing list archive at Nabble.com.
>
>



--
Ricky Clarkson
Java Programmer, AD Holdings
+44 1565 770804
Skype: ricky_clarkson
Google Talk: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

Ben Hutchison-2
In reply to this post by victorspivak
Below is a sketch of how EasyMock works in Java:

class EasyMock {
static expect(something)
}

package classextension;
class EasyMock {
static createMock(aConcreteClass)
}

classextension.EasyMock.expect(something)

Q. is classextension.EasyMock.expect() is being found, when
classextension.EasyMock doesnt define an expect() method?

A. by inheritance of static methods from the superclass.

But Scala sees the 2 EasyMock classes as two distinct (Scala) objects,
no inheritance. Im guessing you are calling expect() on the object
representing classextension.EasyMock?

BTW Whether you mock a trait or not is not relevant.

-Ben


On Wed, Jul 22, 2009 at 11:02 AM, victorspivak<[hidden email]> wrote:

>
> Ben,
>
> I've read the Jan response.  But I do not think it explains the behavior
> that I observe. The mocking of concrete classes is done by classextension
> package (BTW, I have included it) and if I do not include it the Java
> compiler compiles the code but during run time it generates an error.  Also
> I tried to use a trait (in Java world it is an interface) and it does not
> require classextension.  I still get the same error - could not resolve the
> expect method.  It is somehow related to the definition of the expect
> method.  All examples for using EasyMock with Scala that I found in the Net
> do not use expect method.
>
> Victor
>
> Ben Hutchison wrote:
>>
>> On Wed, Jul 22, 2009 at 4:49 AM, victorspivak<[hidden email]>
>> wrote:
>> I am just curious
>>> what wrong is EasyMock in Scala world and what I wromg doing :(
>>>
>>
>> I think Jan has already explained why. Make sure you understand what
>> he meant by:
>>
>> "The EasyMock class (from package *.classextension) extends the normal
>> EasyMock class where expect is implemented. I would guess there is no
>> static method "inheritence" in scala, so scalac does not see the
>> expect method."
>>
>> Ie there are 2 EasyMock classes in EasyMock. One inherits from the
>> other. Java statics implicitly inherit. Scala's dont (Im guessing
>> here).
>>
>> -Ben
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Scala-and-EasyMock-tp24579481p24598399.html
> Sent from the Scala - User mailing list archive at Nabble.com.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

Jan Lohre
In reply to this post by victorspivak
Hi,

I will try it one more time:
The error message you posted "value expect is not a member of object classextenssion.this.EasyMock"
quite clearly shows you are calling org.easymock.classextension.EasyMock.expect, as I already explained this cannot work from Scala because there is no static method "inheritance" in Scala.

Kind regards,
Jan

2009/7/22 victorspivak <[hidden email]>

Ben,

I've read the Jan response.  But I do not think it explains the behavior
that I observe. The mocking of concrete classes is done by classextension
package (BTW, I have included it) and if I do not include it the Java
compiler compiles the code but during run time it generates an error.  Also
I tried to use a trait (in Java world it is an interface) and it does not
require classextension.  I still get the same error - could not resolve the
expect method.  It is somehow related to the definition of the expect
method.  All examples for using EasyMock with Scala that I found in the Net
do not use expect method.

Victor

Ben Hutchison wrote:
>
> On Wed, Jul 22, 2009 at 4:49 AM, victorspivak<[hidden email]>
> wrote:
> I am just curious
>> what wrong is EasyMock in Scala world and what I wromg doing :(
>>
>
> I think Jan has already explained why. Make sure you understand what
> he meant by:
>
> "The EasyMock class (from package *.classextension) extends the normal
> EasyMock class where expect is implemented. I would guess there is no
> static method "inheritence" in scala, so scalac does not see the
> expect method."
>
> Ie there are 2 EasyMock classes in EasyMock. One inherits from the
> other. Java statics implicitly inherit. Scala's dont (Im guessing
> here).
>
> -Ben
>
>

--
View this message in context: http://www.nabble.com/Scala-and-EasyMock-tp24579481p24598399.html
Sent from the Scala - User mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Scala and EasyMock

victorspivak
Thank everyone.  You are right and I did not know that Scala does not support static method inheritance.  IntelliJ Scala plugin confuses me because the plugin shows that expect is a valid method in this context. damn it

Now I have a simple workaround.  I created a Java Facade class that provides this static method:
public class EasyMockJavaFacade
{
        public static <T> IExpectationSetters<T> expect(T value)
        {
            return EasyMock.expect(value);
        }

}

Now in my code instead of using the original expect I use  EasyMockJavaFacade.expect and everything is fine.

Victor


Jan Lohre wrote
Hi,

I will try it one more time:
The error message you posted "value expect is not a member of object
classextenssion.this.EasyMock"
quite clearly shows you are calling
org.easymock.classextension.EasyMock.expect, as I already explained this
cannot work from Scala because there is no static method "inheritance" in
Scala.

Kind regards,
Jan

2009/7/22 victorspivak <victor.spivak@gmail.com>

>
> Ben,
>
> I've read the Jan response.  But I do not think it explains the behavior
> that I observe. The mocking of concrete classes is done by classextension
> package (BTW, I have included it) and if I do not include it the Java
> compiler compiles the code but during run time it generates an error.  Also
> I tried to use a trait (in Java world it is an interface) and it does not
> require classextension.  I still get the same error - could not resolve the
> expect method.  It is somehow related to the definition of the expect
> method.  All examples for using EasyMock with Scala that I found in the Net
> do not use expect method.
>
> Victor
>
> Ben Hutchison wrote:
> >
> > On Wed, Jul 22, 2009 at 4:49 AM, victorspivak<victor.spivak@gmail.com>
> > wrote:
> > I am just curious
> >> what wrong is EasyMock in Scala world and what I wromg doing :(
> >>
> >
> > I think Jan has already explained why. Make sure you understand what
> > he meant by:
> >
> > "The EasyMock class (from package *.classextension) extends the normal
> > EasyMock class where expect is implemented. I would guess there is no
> > static method "inheritence" in scala, so scalac does not see the
> > expect method."
> >
> > Ie there are 2 EasyMock classes in EasyMock. One inherits from the
> > other. Java statics implicitly inherit. Scala's dont (Im guessing
> > here).
> >
> > -Ben
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Scala-and-EasyMock-tp24579481p24598399.html
> Sent from the Scala - User mailing list archive at Nabble.com.
>
>