Skip to content

Latest commit

 

History

History
65 lines (53 loc) · 2.14 KB

how_to.md

File metadata and controls

65 lines (53 loc) · 2.14 KB

Peel

This is for a method where the blocking part is at the outside (top or bottom) of the method

  1. Call the Method Example: Method(param1)
  2. Select everything that isn't the problem
  3. Extract into public method called Method2
  4. Call Method2 instead Example:Method2(newParams)

Slice

This is for method where the blocking part is in the middle of the method

  1. Call the Method passing null for all params Example: Method(param1)
  2. See the failing error:
    Example: Error when calling object.Method(param1,param2);
  3. Pass in a mock for the object where the call is failing
  4. See the new failing error:
    Example: Unexpected call to object.Method(param1,param2);
  5. add Mock behavior for that call
  6. repeat

Mock Example

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());

snippet source | anchor

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

snippet source | anchor

Peel & Slice

  1. Call Method
  2. See Problem
  3. Solve Problem
    1. If at Top or Bottom
      1. Peel
    2. If in Middle
      1. Slice
  4. Repeat until done