I am using EasyMock to write unit tests for my blackjack game.
But I get java.lang.IllegalArgumentException: Cannot subclass final class class com.blackjack.game.cards.Card
error.
Although, I feel I am doing it the right way. Here is my testclass :
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.easymock.EasyMock;
import org.easymock.EasyMockRunner;
import org.easymock.EasyMockSupport;
@RunWith(EasyMockRunner.class)
public class handTest extends EasyMockSupport{
private Hand hand;
private Card seven, nine, ten, jack, ace;
@Before
public void setUp() throws Exception
{
seven = EasyMock.createNiceMock(Card.class);
EasyMock.expect(seven.getValue()).andStubReturn(7);
EasyMock.expect(seven.toString()).andStubReturn("seven value: 7");
}
@Test
public void testTotalHandValueByAddingNumbers() {
replayAll();
hand.addCard(seven);
assertEquals(27, hand.getTotal());
}
}
I would be glad, if somebody could help me run this. It's been a while since I have written unit tests.
Edit: I have both of Objenesis and cglib in my classpath.
Thanks