This is for a method where the blocking part is at the outside (top or bottom) of the method
- Call the Method
Example:
Method(param1)
- Select everything that isn't the problem
- Extract into public method called
Method2
- Call
Method2
instead Example:Method2(newParams)
This is for method where the blocking part is in the middle of the method
- Call the Method passing null for all params
Example:
Method(param1)
- See the failing error:
Example: Error when callingobject.Method(param1,param2);
- Pass in a mock for the
object
where the call is failing - See the new failing error:
Example: Unexpected call toobject.Method(param1,param2);
- add Mock behavior for that call
- repeat
Note: EasyMock requires the expected calls to be in order. Because of this if you use the .times(x)
they need to be sequential calls
var listMock = createStrictMock(List.class);
expect(() -> listMock.size()).andReturn(6);
finalizeExpectations(listMock);
Assertions.assertEquals(6, listMock.size());
This also works for methods that return void
var listMock = createStrictMock(List.class);
expect(() -> listMock.clear());
finalizeExpectations(listMock);
listMock.clear();
//listMock.clear(); this would throw an exception
- Call Method
- See Problem
- Solve Problem
- If at Top or Bottom
- Peel
- If in Middle
- Slice
- If at Top or Bottom
- Repeat until done