Mock abstract class

View: New views
2 Messages — Rating Filter:   Alert me  

Mock abstract class

by Sam Khan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I'm attempting to mock an abstract class but am receiving
the following error:
java.lang.IllegalArgumentException: ht.biz.search.hotel.HotelSearchStrategy
is not an interface
        at java.lang.reflect.Proxy.getProxyClass(Proxy.java:362)
        at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
        at
org.jmock.lib.JavaReflectionImposteriser.imposterise(
JavaReflectionImposteriser.java:31)
        at org.jmock.Mockery.mock(Mockery.java:139)
        at org.jmock.Mockery.mock(Mockery.java:120)
        ....

I'm using JUnit3 & JMock2 - my code is as follows:
import org.jmock.integration.junit3.MockObjectTestCase;
...
public class HotelContributionMarginTest extends MockObjectTestCase {
    private HotelContributionMargin hotelCM;
    final HotelRoom hotelRoom = mock(HotelRoom.class);
    final HotelSearchStrategy searchStrategy = mock(HotelSearchStrategy.class);

    public void setUp() {
        hotelCM = new HotelContributionMargin(hotelRoom, searchStrategy, null);
    }
    public void testSomething() {
       assertEquals(0f, hotelCM.calculate(5));
    }
}
I've read up on this issue and know I need to use the cglib jar. I've tried all
sorts of combinations with it but no joy. Could someone kindly point out where
I'm going wrong?
Cheers,Sam


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



RE: Mock abstract class

by Frederick, Joel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think you need to add the following line prior to mocking your classes
        setImposteriser(ClassImposteriser.INSTANCE);
.

For more information see http://jmock.org/mocking-classes.html

 

-----Original Message-----
From: news [mailto:news@...] On Behalf Of Sam Khan
Sent: Monday, June 22, 2009 1:30 PM
To: user@...
Subject: [jmock-user] Mock abstract class

Hello,
I'm attempting to mock an abstract class but am receiving the following error:
java.lang.IllegalArgumentException: ht.biz.search.hotel.HotelSearchStrategy
is not an interface
        at java.lang.reflect.Proxy.getProxyClass(Proxy.java:362)
        at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
        at
org.jmock.lib.JavaReflectionImposteriser.imposterise(
JavaReflectionImposteriser.java:31)
        at org.jmock.Mockery.mock(Mockery.java:139)
        at org.jmock.Mockery.mock(Mockery.java:120)
        ....

I'm using JUnit3 & JMock2 - my code is as follows:
import org.jmock.integration.junit3.MockObjectTestCase;
...
public class HotelContributionMarginTest extends MockObjectTestCase {
    private HotelContributionMargin hotelCM;
    final HotelRoom hotelRoom = mock(HotelRoom.class);
    final HotelSearchStrategy searchStrategy = mock(HotelSearchStrategy.class);

    public void setUp() {
        hotelCM = new HotelContributionMargin(hotelRoom, searchStrategy, null);
    }
    public void testSomething() {
       assertEquals(0f, hotelCM.calculate(5));
    }
}
I've read up on this issue and know I need to use the cglib jar. I've tried all sorts of combinations with it but no joy. Could someone kindly point out where I'm going wrong?
Cheers,Sam


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email