Я новичок в jMock, поэтому я пробую это на простом примере.Я не могу понять, почему это не работает, хотя.Вот класс, который я тестирую:
package com.application;
import com.domain.Coordinate;
import com.domain.Playable;
public class ChessFacade {
private final Playable board;
public ChessFacade(Playable aBoard) {
board = aBoard;
}
public void showPotentialMoves(Coordinate aCoordinate) {
board.getTileOccupancy(aCoordinate);
}
}
А вот мой тест Mock Object:
package unit.application;
import application.ChessFacade;
import com.domain.Coordinate;
import com.domain.Playable;
import junit.framework.TestCase;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.runner.RunWith;
@RunWith(JMock.class)
public class ChessFacadeTest extends TestCase {
public void testFacadeGetsPotentialMovesFromBoard() {
Mockery context = new JUnit4Mockery();
final Playable mockBoard = context.mock(Playable.class);
ChessFacade facade = new ChessFacade(mockBoard);
final Coordinate locationToShow = new Coordinate(0, 0);
facade.showPotentialMoves(locationToShow);
context.checking(new Expectations() {{
oneOf(mockBoard).getTileOccupancy(locationToShow);
}});
context.assertIsSatisfied();
}
}
Ошибка, которую я получаю:
Testcase: testFacadeGetsPotentialMovesFromBoard(unit.application.ChessFacadeTest): Caused an ERROR
unexpected invocation: playable.getTileOccupancy(<Coordinate{row=0column=0}>)
no expectations specified: did you...
- forget to start an expectation with a cardinality clause?
- call a mocked method to specify the parameter of an expectation?
what happened before this: nothing!
java.lang.AssertionError: unexpected invocation: playable.getTileOccupancy(<Coordinate{row=0column=0}>)
no expectations specified: did you...
- forget to start an expectation with a cardinality clause?
- call a mocked method to specify the parameter of an expectation?
what happened before this: nothing!
at org.jmock.internal.InvocationDispatcher.dispatch(InvocationDispatcher.java:56)
at org.jmock.internal.InvocationDispatcher.dispatch(InvocationDispatcher.java:56)
at org.jmock.Mockery.dispatch(Mockery.java:218)
at org.jmock.Mockery.access$000(Mockery.java:43)
at org.jmock.Mockery$MockObject.invoke(Mockery.java:258)
at org.jmock.internal.InvocationDiverter.invoke(InvocationDiverter.java:27)
at org.jmock.internal.FakeObjectMethods.invoke(FakeObjectMethods.java:38)
at org.jmock.lib.JavaReflectionImposteriser$1.invoke(JavaReflectionImposteriser.java:33)
at $Proxy0.getTileOccupancy(Unknown Source)
at application.ChessFacade.showPotentialMoves(ChessFacade.java:15)
at unit.application.ChessFacadeTest.testFacadeGetsPotentialMovesFromBoard(ChessFacadeTest.java:22)